1

I am writing my PhD thesis in LaTeX. When I tried to center the section titles, awkwardly, it compiles without table of contents but whenever I write \tableofcontents an error occurs.

For centering, I wrote down

\usepackage{titlesec}
\titleformat{\section}[hang]{\normalfont\bfseries\filcenter}{\thesection}{1em}{}
\titleformat{\subsection}[hang]{\normalfont\bfseries}{\thesubsection}{1em}{}

Can anyone help please?

1 Answers1

2

Titlesec defines several shapes for section titles. Among which:

  • [hang] is LaTeX default shape for section: label and section title aligned, staring from the left margin;
  • [block] puts label and section title in a paragraph. Useful for centred section titles or with picture inclusion, for instance;
  • [display] outs the label in a paragraph of its own, like the default \chapter;
  • [framed]: like display, but framed.

For the alignment of titles, titlesec defines commands such as \filcenter, \filleftor \filright, to be used preferably to \centering, \raggedright or \raggedleft (there are small differences as to spacing).

So here, you can write

\titleformat{\section}[block]{\normalfont\bfseries\filcenter}{\thesection}{1em}{}

As nice classical variant,(for my taste…) is this:

\titleformat{\section}[block]{\normalfont\scshape\filcenter}{\§\,\thesection}{1em}{}
Bernard
  • 271,350