5

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!

The section "Solving Difficult Linear Equations" is not indented from the chapter "Fundamental Algebraic Skills"

3
  • What document class are you using?
    – Werner
    Commented May 7, 2012 at 6:11
  • I am using the report document class.
    – ab217
    Commented May 7, 2012 at 6:19
  • Your tip with \setcounter{secnumdepth}{0} helped me a lot. Exactly what I was looking for, since I have no TOC. Thank you! Commented Jul 14, 2015 at 7:42

2 Answers 2

3

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:

enter image description here

\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.

3

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.

You must log in to answer this question.

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