[Tex/LaTex] Turn off Section Numbering without Affecting TOC Indentation

indentationsectioningtable of contents

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"

Best Answer

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.

Related Question