5

Hello I am trying to get rid of some of the numbers on the left side of the table of contents entries. I am using the article class and I would like to eliminate numbers left of "sections" but not "subsections". So, in the picture below, I would like to keep "1.1, 1.2, etc" but not "1"

enter image description here

This also happens in the document itself, with each new section it lists the number to the left. I would like to clear those but still keep the subsection numbers.

I have taken a look at tocloft but I could not make sense of it. If you could give any help, that would be great. I am using Texstudio and here is what my doc looks like right now:

\documentclass[12pt, a4paper]{article}
\usepackage{baskervald}
\usepackage[T1]{fontenc}
\usepackage[notes]{biblatex-chicago}
\DefineBibliographyStrings{english}{references = {Works Cited}}
\DeclareBibliographyCategory{primary}
\usepackage{filecontents}
\usepackage{microtype}
\usepackage{url}
\usepackage{makeidx}
\usepackage{indentfirst}
\makeindex
\addbibresource{bibliography.bib}
\begin{document}
\tableofcontents
\newpage
\section{Part I}
\printbibliography[title={Primary Works},category=primary]
\end{document}

2 Answers 2

11

Here's a minimal version of your document; the important code is between \makeatletter and \makeatother: basically we call \l@section, which is responsible for typesetting the entry in the table of contents after having neutralized \numberline. Then we redefine \@seccntformat which is responsible for printing the number next to the section titles (at all levels): since we define only \sectionformat, with \section{Part I} no number will be printed.

\documentclass[12pt, a4paper]{article}

\makeatletter
\let\latexl@section\l@section
\def\l@section#1#2{\begingroup\let\numberline\@gobble\latexl@section{#1}{#2}\endgroup}
\def\@seccntformat#1{\ifcsname #1format\endcsname\else\csname the#1\endcsname\quad\fi}
\def\sectionformat{}

\makeatother

\usepackage{hyperref}

\begin{document}
\tableofcontents
\newpage
\section{Part I}
\subsection{abc}
\subsection{def}
\end{document}

Notice that hyperref should be loaded after the modification of \l@section (if you want to load it, of course).

enter image description here

enter image description here

The red rectangles are due to hyperref.

However I find it bad style writing “Part I” and then using an arabic number for the section.

9
  • That answer only gets rid of section numbering in the table of contents. I don't think the OP wants section numbering in the body, either...
    – TSB
    Jul 3, 2012 at 22:58
  • @TSB This was not specified. :)
    – egreg
    Jul 3, 2012 at 23:05
  • Yes it was. "This also happens in the document itself, with each new section it lists the number to the left. I would like to clear those but still keep the subsection numbers."
    – TSB
    Jul 3, 2012 at 23:05
  • @TSB You're right. Fixed.
    – egreg
    Jul 3, 2012 at 23:17
  • Thank you, this is great! I had no idea how to go about this :) Jul 4, 2012 at 8:06
4

(Edited according to egreg's comment, except I still prefer \phantomsection before the section command itself.) This code works, but someone else could probably make a simpler version.

\documentclass[12pt,a4paper]{article}

\usepackage{hyperref}

\begin{document}

\tableofcontents

\newpage

\phantomsection
\section*{Part I}
\addcontentsline{toc}{section}{Part I}
\stepcounter{section}
\subsection{abc}
\subsection{def}

\phantomsection
\section*{Part II}
\addcontentsline{toc}{section}{Part II}
\stepcounter{section}
\subsection{ghi}
\subsection{jkl}

\end{document}
3
  • Of course it would be better to define a \Section macro doing the work.
    – egreg
    Jul 3, 2012 at 23:16
  • Definitely, yes.
    – TSB
    Jul 3, 2012 at 23:29
  • Thank you, this is an interesting idea too, using the \phantomsection. I will keep this mind for the future. Thanks! Jul 4, 2012 at 8:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .