8

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
  \csname the#1\endcsname\quad
  \fi}
\makeatother

Mine:

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

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

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}

enter image description here

  • 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
4

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
  \csname the#1\endcsname\quad
  \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
  \csname the#1\endcsname\quad
  \fi\fi\fi}
\makeatother

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

Output

enter image description here

  • 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
3

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}
\newcommand{\prepend@section}{\thesection\quad}
\newcommand{\prepend@subsection}{\thesubsection\quad}
\newcommand{\prepend@subsubsection}{\thesubsubsection\quad}
\makeatother

If you want to remove the number in front of subsubsection titles, but keep it in the table of contents (which could be a reason for going this way instead of using secnumdepth), just comment out the \prepend@subsubsection line.

What happens is that \subsubsection will execute \@seccntformat{subsubsection} which in turn will do \csname prepend@subsubsection\endcsname; if the line is commented out, no definition for \prepend@subsubsection is available, so TeX will consider the \csname...\endcsname construction equivalent to \relax, so it will do nothing.

1

Or the simple option - use the * version. You have to do it with each section/subsection etc. but many environments have an option where * suppresses the numbering. E.g. \section*{Introduction}.

  • The \Section*{} does not show up in the ToC :( – Altoyr May 13 '15 at 7:41

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.