Page LayoutCenter Part Headings in ToC

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
Reza
Posts: 4
Joined: Sat Dec 10, 2011 1:35 am

Center Part Headings in ToC

Post by Reza »

Hi,

how can I centre \part headings in my table of contents?


Regards
Reza
Last edited by Reza on Sat Dec 10, 2011 11:29 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10320
Joined: Mon Mar 10, 2008 9:44 pm

Re: Center Part Headings in ToC

Post by Stefan Kottwitz »

Hi Reza,

welcome to the board!

It depends on the document class you are using. Which one is it?

Stefan
LaTeX.org admin
Reza
Posts: 4
Joined: Sat Dec 10, 2011 1:35 am

Re: Center Part Headings in ToC

Post by Reza »

Hi Stefan,
Thank you for your reply. Much appreciated.

I am using \documentclass[12pt,a4paper]{report}

Regards,
Reza
User avatar
Stefan Kottwitz
Site Admin
Posts: 10320
Joined: Mon Mar 10, 2008 9:44 pm

Center Part Headings in ToC

Post by Stefan Kottwitz »

Hi Reza,

here's a quick solution. It redefines the original part TOC entry, uses \hspace*{\fill} on the left and on the right of the heading, to get it centered.

Code: Select all

\documentclass[12pt,a4paper]{report}
\makeatletter
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \setlength\@tempdima{3em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
       \hspace*{\fill}\centering\large\bfseries #1\hspace*{\fill}\llap{#2}}\par
       \nobreak
         \global\@nobreaktrue
         \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}
\makeatother
\begin{document}
\tableofcontents
\part{One}
\chapter{First chapter}
\end{document}
Stefan
LaTeX.org admin
Reza
Posts: 4
Joined: Sat Dec 10, 2011 1:35 am

Re: Center Part Headings in ToC

Post by Reza »

Stephan,
Magic. It is working. Thank you so much.

Regards,
Reza
Post Reply