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 Answers2

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.

egreg
  • 1,121,712
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}
TSB
  • 223