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

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

1
  • Add also \setcounter{tocdepth}{2} if you want a table of contents with the sections and subsections, but not the deeper levels.
    – Fran
    Commented May 13, 2015 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

3
  • 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. Commented May 13, 2015 at 7:01
  • @SailorChibi OK. You didn't mention the ToC in your question... :-) Commented May 13, 2015 at 7:02
  • You are right, I didn't sed, that the code from my linked answer doesn't affect the ToC Commented May 13, 2015 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.

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

1
  • 1
    The \Section*{} does not show up in the ToC :( Commented May 13, 2015 at 7:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .