5

Apologies if this has already been asked and answered but I did do a fair amount of looking and couldn't find anything.

\documentclass{article}
\begin{document}
\tableofcontents
\section{Section One}
blah 
\subsection{Subsection One}
blah blah
\section{Section Two}
blah blah blah
\end{document}

All I want is for the above MWE to come out as (in the document itself):

Section One

blah

1.1 Subsection One

blah blah

Section Two

blah blah blah

... and in the table of contents:

  1. Section One 1.1 Subsection One
  2. Section Two

So basically, using:

\section*{Section One}
\subsection{Subsection One}
\section*{Section Two}

... works for what I want for the document itself (i.e. using asterisks with the sections but not with the subsections), but this does not work with the table of contents. I still want the numbers in the table of contents, and no matter what I do with \addtocontents or \addcontentsline{toc}{section}{} etc., nothing seems to work.

Any help would be greatly appreciated.

EDIT To those saying this is confusing, I just want the numbering to be absent in the main document for the SECTION, NOT the subsections (and subsubsections etc.), of which there are many. This is because I want there to be a Section followed by a quote, followed by a bunch of (numbered) subsections in the main document ... but I still want the TOC to have the numbering for the Sections. I am well aware that the "book" class is probably easier for this, but I want to use article for other features.

2
  • Sorry, this is quite confusing to use numbers in the ToC but not in the document body. And you don't mean \tableofcontents before \begin{document}, I assume? ;-)
    – user31729
    Commented May 17, 2017 at 11:16
  • @ChristianHupfer I've edited the MWE to correct the mistake with \tableofcontents being before \begin{document}
    – Ben A
    Commented May 17, 2017 at 11:21

3 Answers 3

3

REVISED

\documentclass{article}
\newcommand\Decide[1]{#1}
\makeatletter
\def\sectionsuffix      {}
\def\subsectionsuffix   {\quad}
\def\subsubsectionsuffix{\quad}
\def\paragraphsuffix    {\quad}
\renewcommand\@seccntformat[1]{\csname the#1\endcsname\csname#1suffix\endcsname}
\renewcommand\thesection{\protect\Decide{\@arabic\c@section}}
\renewcommand\thesubsection{\@arabic\c@section.\@arabic\c@subsection}
\makeatother
\begin{document}
\tableofcontents
\renewcommand\Decide[1]{}

\section{Section One}
blah 
\subsection{Subsection One}
blah blah
\section{Section Two}
blah blah blah
\end{document}

enter image description here

ORIGINAL APPROACH

I don't recommend it, because it is very confusing.

The macro \@seccntformat sets the appearance of the section numbering. So here, after the \tableofcontents, I nullify the macro, so that no formatting is done on the section numbering.

\documentclass{article}
\begin{document}
\tableofcontents
\makeatletter
\renewcommand\@seccntformat[1]{}
\makeatother
\section{Section One}
blah 
\subsection{Subsection One}
blah blah
\section{Section Two}
blah blah blah
\end{document}

enter image description here

5
  • Thank you but I'm sorry: this doesn't work, because there isn't a number for Subsection One, i.e.: "1.1 Subsection One"
    – Ben A
    Commented May 17, 2017 at 11:25
  • @BenA So you only want it for \section, but not the lower sectioning levels? Commented May 17, 2017 at 11:26
  • Yes, that's correct. I've just edited my OP.
    – Ben A
    Commented May 17, 2017 at 11:27
  • @BenA Please see my edit. Commented May 17, 2017 at 11:37
  • @StevenBSegletes Thanks! This now works. I had no idea it would require so much tweaking... I've marked this as the answer.
    – Ben A
    Commented May 17, 2017 at 11:42
3

You could use something like this, but i am not sure if it is what you want:

\begin{document}
\tableofcontents
\section*{Section 1}
\addcontentsline{toc}{section}{Section 1}
\addtocounter{section}{1}
blah
\subsection{Subsection 1}
blah blah
\section{Section 2}
blah blah
\end{document}

which would result in this:

Result (font is cmbright)

3
  • Thank you, but this doesn't quite work: I had to simplify my MWE and it seems to conflict with something else I've got in my preamble or one of my style files, and they're so out of control that I can't figure out what. One of the other answers seems to work, though.
    – Ben A
    Commented May 17, 2017 at 11:43
  • @BenA: If your MWE is not the version you have it's not the fault of user133314 when his/her solution solves the initially posted problem ;-)
    – user31729
    Commented May 17, 2017 at 11:56
  • @ChristianHupfer It's fine i see what he wanted and my solution simply doesn't do the job :D
    – user133314
    Commented May 17, 2017 at 12:05
2

This is very easy using KOMA-Script class scrartcl. If you want, you can change the defaults of the class to look like standard class article:

\documentclass[emulatestandardclasses]{scrartcl}% emulate article with scrartcl
\renewcommand*{\sectionformat}{}% dont show section numbers in section heading
\begin{document}
\tableofcontents
\section{Section One}
blah 
\subsection{Subsection One}
blah blah
\section{Section Two}
blah blah blah
\end{document}

Result:

result with scrartcl emulating article

If you also don't want the section number in a running head (page style headings) you can add:

\renewcommand*{\sectionmarkformat}{}

You must log in to answer this question.

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