I have a final report that I am writing in LaTeX. I have a code to make the section headings appear in the center of the page (thanks to Jubobs):

\titleformat{\section}
{\vspace*{\fill}\centering\normalfont\Large\bfseries}
{\thesection}
{1em}
{\Large}
[\vspace*{\fill}\newpage]


This unfortunately creates two entries in the tableofcontents page. Deleting this code solves the ToC problem, but I still want the section headings to be centered on the page. How can this be resolved?

MWE :

\documentclass{article}
\usepackage{enumerate,a4wide,graphicx,pdfpages,titlesec}
\title{Final Report}
\setcounter{secnumdepth}{0}
\begin{document}

\titleformat{\section}
{\vspace*{\fill}\centering\normalfont\Large\bfseries}
{\thesection}
{1em}
{\Large}
[\vspace*{\fill}\newpage]

\begin{titlepage}
\begin{center}
\includegraphics[scale=0.15]{name}\\[0.2cm]
{\Large XYZ}\\[0.2cm]
{\Large ABC}\\[2.5cm]
{\huge \textbf{Final Report}}\\[5cm]
\end{center}
\begin{minipage}{0.5\textwidth}
\begin{flushleft}
\emph{ABC :} \\
\textbf{ABC} \\ ~\\
\emph{XYZ : }\textbf{ABC}
\end{flushleft}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{flushright}
\emph{XYZ :}\\
\textbf{ABC} \\
\emph{XYZ :} \\
\textbf{ABC} \\
\end{flushright}
\end{minipage}
\vfill
\begin{center}
\today
\end{center}
\end{titlepage}

\tableofcontents

\newpage

\section{Test Section}
Test.
\newpage

\section{Test Section 2}
This is a filler.
\newpage
\end{document}

• Since \tableofcontents uses \section*, perhaps you will need to provide a different definition for starred (unnumbered) section; something like \documentclass{article} \usepackage{titlesec} \titleformat{\section} {\vspace*{\fill}\centering\normalfont\Large\bfseries} {\thesection}{1em} {\Large}[\vspace*{\fill}\newpage] \titleformat{name=\section,numberless} {\normalfont\Large\bfseries}{}{0em}{} \newcommand{\sectionbreak}{\clearpage} \begin{document} \tableofcontents \section{test} \end{document} – Gonzalo Medina Mar 18 '13 at 14:40
• Please provide a minimal working example (MWE). Using your code snippet does not show any problem for me. – mafp Mar 18 '13 at 14:43
• Your MWE does not demonstrate any problems. There is no \tableofcontents, and no \section. Please make an MWE that actually has double entries in the ToC. – mafp Mar 18 '13 at 15:01

You can change the class for \section to page to ensure that titles will be on a page of their own; I would also suggest you to define a command to apply the modifications once special unnumbered sections, such as the ToC, LoF, LoT, have been typeset; something along the following lines:

\documentclass{article}
\usepackage{titlesec}

\setcounter{secnumdepth}{0}

\newcommand\sectformat{%
\titleclass{\section}{page}
\titleformat{\section}
{\vfill\centering\normalfont\Large\bfseries}
{}{0em}
{}[\vfill]%
}
\newcommand\sectionbreak{\clearpage}

\begin{document}
\tableofcontents

\sectformat
\section{Test Section One}
Test.

\section{Test Section Two}
Test.

\end{document}


The culprit seems to be the \newpage in this passage:

\titleformat{\section}
{\vspace*{\fill}\centering\normalfont\Large\bfseries}
{\thesection}
{1em}
{\Large}
[\vspace*{\fill}\newpage]


The problem disappears when you remove it. Consider this example (I've removed a number of non-MWE things as well -- there were a lot, actually):

\documentclass{article}
\usepackage{titlesec}
\title{Final Report}
\setcounter{secnumdepth}{0}

\titleformat{\section}
{\vspace*{\fill}\centering\normalfont\Large\bfseries}
{\thesection}
{1em}
{\Large}
[\vspace*{\fill}]

\begin{document}

\tableofcontents

\newpage

\section{Test Section}
\newpage
Test.

\newpage
\section{Test Section 2}
\newpage
This is a filler.
\end{document}


Now you probably still want to have the section headings appear on a separate page (like with \part). There's a couple of ways to do this. You may e.g. have a look a the etoolbox page, which allows you to prepend and append a \newpage to every \section.

• How can I use the etoolbox package, through AtBeginEnvironment? – Anava Jain Mar 18 '13 at 15:41
• @AnavaJain, actually, I just realized etoolbox isn't necessary. Gonzalo's suggestion, which I endorse, is even more elegant and doesn't require an additional package, since you're using titlesec anyway. But etoolbox is a great package nevertheless; something to keep in mind for whenever you need to modify existing commands (and lots of other problems as well). – Nils L Mar 18 '13 at 18:20

I moved the titlesec definition before \begin{document}, and provide a definition for the starred section version, that will be applied to the ToC itself, as Gonzalo suggested. As you don't want section numbers, I removed them directly at the \titleformat definition, and set secnumdepth to 1, so the normal sections and the ToC section can be distinguished.

\documentclass{article}
\usepackage{enumerate,a4wide,graphicx,pdfpages,titlesec}
\title{Final Report}
\setcounter{secnumdepth}{1}
\titleformat{\section}
{\vspace*{\fill}\centering\normalfont\Large\bfseries}
{} % no section number
{1em}
{\Large}
[\vspace*{\fill}\newpage]

%% For the ToC
\titleformat{name=\section,numberless}
{\normalfont\Large\bfseries}
{}
{0em}
{}
\begin{document}
\tableofcontents

\newpage
\section{Test Section}
Test.
\newpage

\section{Test Section 2}
This is a filler.
\newpage
\end{document}

• This solves the ToC problem but the section headings need to be centered on a page and the content to start from the next page which is not happening. – Anava Jain Mar 18 '13 at 15:36
• @AnavaJain Please see the updated version. – mafp Mar 18 '13 at 15:54