0

I'd like to know if there is any way to hide the numbering for subsubsections in the table of contents keeping numbering for sections and subsections. In the picture you can see how it currently looks like.

Thank you

That's how it looks now, I'd like to hide numbering for subsubsections

  • Welcome to TeX.SX! You could use \setcounter{tocdepth}{2}. – Bobyandbob Feb 21 '18 at 22:38
  • Welcome to TeX.SE. Which document class are you using? Should the subsubsections be numbered in the text? – user31729 Feb 21 '18 at 22:38
  • @Bobyandbob: No, \setcounter{tocdepth}{2} would make the subsubsections vanish from ToC -- as far as I understood, the titles of the subsubsections shall still appear in the ToC, but the numbers be removed (although this might be weird) – user31729 Feb 21 '18 at 22:39
1

The \@sect code is relevant for all \section etc. like macros and there is \addcontentsline{toc}{#1}{% \ifnum #2>\c@secnumdepth... checking for the value of secnumdepth. By replacing this \c@secnumdepth by another counter value it is possible to hide the numbering in the ToC.

I've introduced the counter secnumtocdepth for this.

enter image description here

\documentclass{article}


\newcounter{secnumtocdepth}

\setcounter{secnumtocdepth}{2}

\makeatletter
\AtBeginDocument{%

\def\@sect#1#2#3#4#5#6[#7]#8{%
  \ifnum #2>\c@secnumdepth
    \let\@svsec\@empty
  \else
    \refstepcounter{#1}%
    \protected@edef\@svsec{\@seccntformat{#1}\relax}%
  \fi
  \@tempskipa #5\relax
  \ifdim \@tempskipa>\z@
    \begingroup
      #6{%
        \@hangfrom{\hskip #3\relax\@svsec}%
          \interlinepenalty \@M #8\@@par}%
    \endgroup
    \csname #1mark\endcsname{#7}%
    \addcontentsline{toc}{#1}{%
      \ifnum #2>\c@secnumtocdepth \else
        \protect\numberline{\csname the#1\endcsname}%
      \fi
      #7}%
  \else
    \def\@svsechd{%
      #6{\hskip #3\relax
      \@svsec #8}%
      \csname #1mark\endcsname{#7}%
      \addcontentsline{toc}{#1}{%
        \ifnum #2>\c@secnumtocdepth \else
          \protect\numberline{\csname the#1\endcsname}%
        \fi
        #7}}%
  \fi
  \@xsect{#5}}


}
\makeatother

\newcommand{\leveltohide}{2}

\begin{document}
\tableofcontents



\section{First section}
\subsection{Foo subsection}

\subsubsection{Foo subsubsection}


\section{Second section}
\subsection{Foo subsection}

\subsubsection{Foo subsubsection}


\end{document}
| improve this answer | |
0

With a standard class you could use package tocbasic:

\documentclass{article}

\usepackage{tocbasic}
\newcommand\gobble[1]{}
\DeclareTOCStyleEntry[
  entrynumberformat=\gobble,
  numwidth=0pt
]{tocline}{subsubsection}

\begin{document}
\tableofcontents
\section{First section}
\subsection{Foo subsection}
\subsubsection{Foo subsubsection}
\section{Second section}
\subsection{Foo subsection}
\subsubsection{Foo subsubsection}
\end{document}

Result:

enter image description here

This would also work with a KOMA-Script class, but then tocbasic is already loaded by the class.


With a KOMA-Script class you could also use \RedeclareSectionCommand

\documentclass{scrartcl}
\newcommand\gobble[1]{}
\RedeclareSectionCommand[
  tocentrynumberformat=\gobble,
  tocnumwidth=0pt
]{subsubsection}

\begin{document}
\tableofcontents
\section{First section}
\subsection{Foo subsection}
\subsubsection{Foo subsubsection}
\section{Second section}
\subsection{Foo subsection}
\subsubsection{Foo subsubsection}
\end{document}

Or you could redefine \addsubsubsectiontocentry:

\documentclass{scrartcl}

\renewcommand\addsubsubsectiontocentry[2]{%
  \addtocentrydefault{subsubsection}{}{#2}%
}

\begin{document}
\tableofcontents
\section{First section}
\subsection{Foo subsection}
\subsubsection{Foo subsubsection}
\section{Second section}
\subsection{Foo subsection}
\subsubsection{Foo subsubsection}
\end{document}

Result:

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.