10

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

4 Answers4

14

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

karlkoeller
  • 124,410
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.

egreg
  • 1,121,712
2

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

Esme_
  • 657
  • 7
  • 15