46

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.

lockstep
  • 250,273
Tony
  • 461
  • What should happen after a 2nd \section*? Should the numbering start again at 1 or should it continue? – knut Dec 05 '11 at 21:39

3 Answers3

26

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.

Werner
  • 603,163
17

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}
Mico
  • 506,678
  • But without the redefinition of \thesection you still get a numbered section. See also my answer. – knut Dec 05 '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 05 '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 06 '11 at 00: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 '19 at 02: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 '19 at 09:16
  • @Mico I may be missing something obvious, but where can I find the addendum? I see your answer and your response to knut only. – Adam Mar 22 '19 at 17:01
  • @Adam - Umm, I see the addendum just fine. It starts with the string "Addendum to address Adam's follow-up question". Does reloading the page maybe help? – Mico Mar 22 '19 at 18:26
  • It might be good to note that with this solution, section numbers do still show up in the table of contents (if you have one). – Circumscribe May 09 '20 at 06:40
  • @Circumscribe - Thanks. If having to produce a table of contents is required, I would suggest inserting \usepackage{tocloft} \makeatletter \renewcommand\cftsecpresnum{\@gobble} \makeatother in the preamble. It may be desirable to tweak the appearance of the ToC beyond this minimalist step. E.g., one could further run \setlength\cftsecnumwidth{0em} \setlength\cftsubsecindent{0em} \setlength\cftsubsecnumwidth{1.5em} \setlength\cftsubsubsecindent{1.5em} \setlength\cftsubsubsecnumwidth{2em}. Before getting too specific, though, I'd rather hear back from the OP first. – Mico May 09 '20 at 08:16
  • 1
    @Mico – The OP was last seen in December of 2011 and they never got around to accepting any of the answers, so I think the chance of a reply from them is likely slim :) / :(. – Circumscribe May 09 '20 at 08:30
  • @Circumscribe -- Well, are you satisfied with the additional information I provided? – Mico May 09 '20 at 08:32
  • 1
    @Mico – I am. This completely fixes the problem. – Circumscribe May 09 '20 at 08:39
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}
knut
  • 8,838