I am new to LaTex and I am writing a document where I do not want my sections to be numbered. I did a quick google search and found this line of code to turn them off: \setcounter{secnumdepth}{0} % Turns off numbering for sections.
However, when using this, I notice that my second level items in my TOC are not indenting properly. You can see here that I have a chapter and underneath that chapter is the first section; however, it is on the same indentation level as the chapter. Is there a way to correct this so my sections appear indented? Also if there is a better way to disable section numbering, please let me know. Thanks!
2 Answers
The following suggestion re-inserts the \numberline
component of the ToC entry for all sectional units higher than secnumdepth
. So, you'll get the original spacing of \section
, \subsection
,... in the ToC:
\documentclass{report}
\setcounter{secnumdepth}{0}% % Turns off numbering for sections
\makeatletter
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\patchcmd{\@sect}% <cmd>
{\else \protect}% <search>
{\protect\numberline{}\else\protect}% <replace>
{}{}% <success><failure>
\makeatother
\begin{document}
\tableofcontents
\chapter{Fundamental Algebraic Skills}
\section{Solving Difficult Linear Equations}
\subsection{Linear Equations that Contain Fractions}
\end{document}
etoolbox
is used to patch \@sect
, adding an empty \numberline
as part of the test on secnumdepth
.
You can probably be satisfied with
\makeatletter
\renewcommand{\l@section}{\@dottedtocline{1}{2.5em}{2.3em}}
\makeatother
The usual definition is
\@dottedtocline{1}{1.5em}{2.3em}
so your section will be 1em more to the right than before.
\setcounter{secnumdepth}{0}
helped me a lot. Exactly what I was looking for, since I have no TOC. Thank you!