# Remove numbering from Section and Subsection

I found this answer to remove the numbering from sections, but I also don't need numbering on sub- and subsubsections.

I tried to add a second def but then the number on Section is showed again. I am fairly new to Latex and I don't really know what is going on in this code block.

Original:

\makeatletter
\def\@seccntformat#1{%
\expandafter\ifx\csname c@#1\endcsname\c@section\else
\fi}
\makeatother

Mine:

\makeatletter
\def\@seccntformat#1{%
\expandafter\ifx\csname c@#1\endcsname\c@section\else
\fi}

\def\@seccntformat#1{%
\expandafter\ifx\csname c@#1\endcsname\c@subsection\else
\fi}
\makeatother

Since you don't want numbering, use \setcounter{secnumdepth}{0}

\documentclass{article}
\setcounter{secnumdepth}{0}
\begin{document}
\section{A section}
\subsection{A sub section}
\subsubsection{A sub sub section}
\end{document}

• Add also \setcounter{tocdepth}{2} if you want a table of contents with the sections and subsections, but not the deeper levels. – Fran May 13 '15 at 20:21

You have to nest the definition in this way:

\makeatletter
\def\@seccntformat#1{%
\expandafter\ifx\csname c@#1\endcsname\c@section\else
\expandafter\ifx\csname c@#1\endcsname\c@subsection\else
\expandafter\ifx\csname c@#1\endcsname\c@subsubsection\else
\fi\fi\fi}
\makeatother

MWE

\documentclass{article}

\makeatletter
\def\@seccntformat#1{%
\expandafter\ifx\csname c@#1\endcsname\c@section\else
\expandafter\ifx\csname c@#1\endcsname\c@subsection\else
\expandafter\ifx\csname c@#1\endcsname\c@subsubsection\else
\fi\fi\fi}
\makeatother

\begin{document}
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\end{document}

Output

• Your "code" works too but it still displays the numbering in the table of contents, so in that case @HarishKumar s answer works better for me. – Altoyr May 13 '15 at 7:01
• @SailorChibi OK. You didn't mention the ToC in your question... :-) – karlkoeller May 13 '15 at 7:02
• You are right, I didn't sed, that the code from my linked answer doesn't affect the ToC – Altoyr May 13 '15 at 7:03

That code is aimed to just do the removal from sections. However, in order to remove numbering, the easiest way is to set secnumdepth to 0:

\setcounter{secnumdepth}{0}

I'll show also how to improve the code you were given for doing several tests.

\makeatletter
\renewcommand\@seccntformat[1]{\csname prepend@#1\endcsname}