17

This is the barebones of my document:

\documentclass[12pt]{article}

\begin{document}

\begin{center}
    \textbf{\LARGE{Topic I}}
 \end{center}

\section{Section I}
content

\section{Section II}
content

\subsection{Subsection I} 
content

\subsection{Subsection II}
content

\section{Section III}
content

\begin{center}
    \textbf{\LARGE{Topic II}}
 \end{center}

\section{Section I}
content

\section{Section II}
content

\subsection{Subsection I} 
content

\subsection{Subsection II}
content

\section{Section III}
content

\end{document}

which displays like

this.

I want the section numbering to restart at Topic II.

henrique
  • 6,616

2 Answers2

15

Instead of providing headings manually (which can be prone-error and implies a lot of manual intervention), you can redefine the \part command to give the desired layout; then you can make the section counter reset every time part is incremented:

\documentclass[12pt]{article}

\makeatletter
\@addtoreset{section}{part}
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >\m@ne
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    {\parindent \z@ \raggedright
     \interlinepenalty \@M
     \normalfont\centering
     \ifnum \c@secnumdepth >\m@ne
       \LARGE\bfseries \partname\nobreakspace\thepart
       \par\nobreak
     \fi
     \huge \bfseries #2%
     \markboth{}{}\par}%
    \nobreak
    \vskip 3ex
    \@afterheading}
\renewcommand\partname{Topic}
\makeatother

\begin{document}

\part{}
\section{Section I}
content

\section{Section II}
content

\subsection{Subsection I} 
content

\subsection{Subsection II}
content

\section{Section III}
content

\part{}
\section{Section I}
content

\section{Section II}
content

\subsection{Subsection I} 
content

\subsection{Subsection II}
content

\section{Section III}
content

\end{document}

enter image description here

Adendum:

Using the xpatch package you can simplify the code:

\documentclass[12pt]{article}
\usepackage{xpatch}

\makeatletter
\@addtoreset{section}{part}
\xpatchcmd{\@part}{\normalfont}{\normalfont\centering}{}{}
\xpatchcmd{\@part}{\Large}{\LARGE}{}{}
\renewcommand\partname{Topic}
\makeatother

\begin{document}

\part{}
\section{Section I}
content

\section{Section II}
content

\subsection{Subsection I} 
content

\subsection{Subsection II}
content

\section{Section III}
content

\part{}
\section{Section I}
content

\section{Section II}
content

\subsection{Subsection I} 
content

\subsection{Subsection II}
content

\section{Section III}
content

\end{document}

Adendum 2:

Another variant, using this time the titlesec package to easily customize the \part command, suppressing the "Part #" label and centering the title:

\documentclass[12pt]{article}
\usepackage{titlesec}

\makeatletter
\@addtoreset{section}{part}
\makeatother
\titleformat{\part}[display]
{\normalfont\LARGE\bfseries\centering}{}{0pt}{}

\begin{document}

\part{Polynomials}
\section{Section I}
content

\section{Section II}
content

\subsection{Subsection I} 
content

\subsection{Subsection II}
content

\section{Section III}
content

\part{Functions}
\section{Section I}
content

\section{Section II}
content

\subsection{Subsection I} 
content

\subsection{Subsection II}
content

\section{Section III}
content

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
10
\documentclass[12pt]{article}

\makeatletter
\@addtoreset{section}{part}
\makeatother

\begin{document}

\part{Topic I}

\section{Section I}
content

\section{Section II}
content

\subsection{Subsection I} 
content

\subsection{Subsection II}
content

\section{Section III}
content


\part{Topic II}

\section{Section I}
content

\section{Section II}
content

\subsection{Subsection I} 
content

\subsection{Subsection II}
content

\section{Section III}
content

\end{document}

Note \LARGE does not take an argument and should always include the following end of paragraph so the syntax would be \begin{center}\bfseries\LARGE Topic I\end{center} but using explicit font changes rather than a section head is just not the LaTeX way:-) The formatting for a \part head can be separately customised to use a centred heading if that is desired.

David Carlisle
  • 757,742
  • I'm a LaTeX noob and I can never seem to get things right using the built-in functionality of LaTeX so I just make my own headings lol. – Frank Epps Jul 20 '13 at 00:02
  • can you make it look exactly like what I had? (center "Topic I" and delete the "Part I" headers) – Frank Epps Jul 20 '13 at 00:04
  • @FrankEpps Did you see my answer? ;-) – Gonzalo Medina Jul 20 '13 at 00:05
  • yes I did, I see that it works and it's exactly what I wanted :) but the large mass of code is putting me off... – Frank Epps Jul 20 '13 at 00:06
  • @FrankEpps please see my updated answer. – Gonzalo Medina Jul 20 '13 at 00:11
  • @FrankEpps I could do but then it would look like Gonzalo's answer (well you could make a much simpler version that just did the heading but that does a proper job wrt penalties and page breaks etc. Perhaps you'd prefer something like titlesec package which gives a possibly easier syntax wher eyou can just declare you want part titles centred. – David Carlisle Jul 20 '13 at 00:11