33

I'm working on an article and I don't want to number my sections. However, I do want my subsections and subsubsections to be numbered. Right now my document has this numbering, but the 0 in 0.X.Y should not be there. How can I fix that?

Currently:
Section
0.1 subsection
0.2 subsection
0.2.1 subsubsection
0.3 subsection

Should be:
Section
1. subsection
2. subsection
2.1 subsubsection
3. subsection

This is my code:

\documentclass{article}

\begin{document}

\section*{Section}

\subsection{subsection}

\subsection{subsection}

\subsubsection{subsubsection}
blah
\subsection{subsection}

\end{document}

PS: I did search a on the web and found a lot on this topic, but not a solution to this particular thing.

  • What should happen after a 2nd \section*? Should the numbering start again at 1 or should it continue? – knut Dec 5 '11 at 21:39
23

If you're interested in printing \section{<heading>} in a similar way that \section*{<heading>} would print (that is, flush left and not indented), then titlesec provides an easy interface:

enter image description here

\documentclass{article}
\usepackage{titlesec}% http://ctan.org/pkg/titlesec
\titleformat{\section}%
  [hang]% <shape>
  {\normalfont\bfseries\Large}% <format>
  {}% <label>
  {0pt}% <sep>
  {}% <before code>
\renewcommand{\thesection}{}% Remove section references...
\renewcommand{\thesubsection}{\arabic{subsection}}%... from subsections
\begin{document}

\section{First section}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin rutrum tellus, 
eu luctus dolor commodo eu. Integer pellentesque mollis congue.

\subsection{First subsection}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin rutrum tellus, 
eu luctus dolor commodo eu. Integer pellentesque mollis congue.

\subsection{Second subsection}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin rutrum tellus, 
eu luctus dolor commodo eu. Integer pellentesque mollis congue.

\subsubsection{First subsubsection}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin rutrum tellus, 
eu luctus dolor commodo eu. Integer pellentesque mollis congue.

\subsection{Last subsection}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin rutrum tellus, 
eu luctus dolor commodo eu. Integer pellentesque mollis congue.

\section{Second section}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin rutrum tellus, 
eu luctus dolor commodo eu. Integer pellentesque mollis congue.

\subsection{First subsection}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sollicitudin rutrum tellus, 
eu luctus dolor commodo eu. Integer pellentesque mollis congue.

\end{document}​

This just sets the label separator between the section number and title to 0pt, as well as not printing the number. \normalfont\bfseries\Large is the default formatting for article.

12

Note: I rewrote this answer significantly after becoming aware of Ulrike Fisher's comment to @knut's answer.

There are two steps that need to be taken. The first, straightforward step consists of redefining the \thesubsection macro. The second, less obvious step involves a redefinition of the LaTeX internal macro \@seccntformat, as is explained in the book The LaTeX Companion, 2nd ed. The following MWE applies both steps:

enter image description here

\documentclass{article}

\renewcommand{\thesubsection}{\arabic{subsection}}
\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\quad}%    default
   {\csname #1@cntformat\endcsname}}% enable individual control
\newcommand\section@cntformat{}     % section level 
\makeatother

\begin{document}
\section{First Section}
\subsection{First subsection}
\subsection{Second subsection}
\subsubsection{First subsubsection}
\subsection{Third subsection}
\section{Second Section}
\subsection{A new subsection}
\end{document}

Addendum to address @Adam's follow-up question: To (a) add dots after the subsection (and subsubsection) numbers in the sectioning headers and (b) replace the implicit \quad spacing directive with \space, you would need to provide the following two directives in the preamble, immediately before \makeatother:

\newcommand\subsection@cntformat{\thesubsection.\space}
\newcommand\subsubsection@cntformat{\thesubsubsection.\space}

A revised MWE:

enter image description here

\documentclass{article}

\renewcommand{\thesubsection}{\arabic{subsection}}
\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\quad}%    default
   {\csname #1@cntformat\endcsname}}% enable individual control
\newcommand\section@cntformat{}     % section level 
\newcommand\subsection@cntformat{\thesubsection.\space} % subsection level
\newcommand\subsubsection@cntformat{\thesubsubsection.\space} % subsubsection level
\makeatother

\begin{document}
\section{First Section}
\subsection{First subsection}
\subsection{Second subsection}
\subsubsection{First subsubsection}
\subsection{Third subsection}
\section{Second Section}
\subsection{A new subsection}
\end{document}
  • But without the redefinition of \thesection you still get a numbered section. See also my answer. – knut Dec 5 '11 at 19:14
  • I understand. Then you have the same problem Ulrike mentioned: This will not restart the numbering of the \subsections after the next \section* - but there is no information in the question, what's needed in this case. – knut Dec 5 '11 at 21:38
  • @knut: I just noticed the comment by Ulrike Fisher to your answer. She's right about having to use \section rather than \section*, as otherwise subsection numbers won't get reset in a new section. As my (now thoroughly revised) answer that's based on some code from The LaTeX Companion shows, what's really needed to solve the OP's challenge is both a redefinition of \@seccntformat and a new macro, \section@cntformat -- set here to {}. Interestingly, it is not necesssary to set \thesection to something like {}. Whew, this was a lot harder than it looked like at first! – Mico Dec 6 '11 at 0:24
  • 1
    That is great. However, how can I add the period after the subsection number and keep only one space after? I think "1. First subsection" would look better. – Adam Mar 22 at 2:18
  • @Adam - Please see the addendum I posted to my answer. It provides the code needed to implement your formatting objective for subsection- and subsubsection-level headers. – Mico Mar 22 at 9:16
7

Does this works for you:

\documentclass{article}

\begin{document}

\part*{Section}

\section{subsection}

\section{subsection}

\subsection{subsubsection}
blah
\section{subsection}

\end{document}

Or is there a special reason, why you need sections as sections and subsections as subsection?


Alternative:

\documentclass{article}

\renewcommand{\thesection}{}
\renewcommand{\thesubsection}{\arabic{subsection}}

\begin{document}

\section{Section}

\subsection{subsection}

\subsection{subsection}

\subsubsection{subsubsection}
blah
\subsection{subsection}

\section{Section 2}

\subsection{subsection 2}
This subsection starts again with 1.


\end{document}
  • That does the job, but the size is rather large now. Can you tell me how to keep it the same size as the sections? Thanks :) – Tony Dec 5 '11 at 14:54
  • 3
    This will not restart the numbering of the \subsections after the next \section*. – Ulrike Fischer Dec 5 '11 at 15:21
  • You are right - but it works with \section. I change my answer. – knut Dec 5 '11 at 19:16

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.