Hi,
how can I centre \part headings in my table of contents?
Regards
Reza
Page Layout ⇒ Center Part Headings in ToC
Center Part Headings in ToC
Last edited by Reza on Sat Dec 10, 2011 11:29 am, edited 1 time in total.
NEW: TikZ book now 40% off at Amazon.com for a short time.
- Stefan Kottwitz
- Site Admin
- Posts: 10320
- Joined: Mon Mar 10, 2008 9:44 pm
Re: Center Part Headings in ToC
Hi Reza,
welcome to the board!
It depends on the document class you are using. Which one is it?
Stefan
welcome to the board!
It depends on the document class you are using. Which one is it?
Stefan
LaTeX.org admin
Re: Center Part Headings in ToC
Hi Stefan,
Thank you for your reply. Much appreciated.
I am using \documentclass[12pt,a4paper]{report}
Regards,
Reza
Thank you for your reply. Much appreciated.
I am using \documentclass[12pt,a4paper]{report}
Regards,
Reza
- Stefan Kottwitz
- Site Admin
- Posts: 10320
- Joined: Mon Mar 10, 2008 9:44 pm
Center Part Headings in ToC
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.
Stefan
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}
LaTeX.org admin
Re: Center Part Headings in ToC
Stephan,
Magic. It is working. Thank you so much.
Regards,
Reza
Magic. It is working. Thank you so much.
Regards,
Reza