Page Layout ⇒ Center Part Headings in ToC
Center Part Headings in ToC
how can I centre \part headings in my table of contents?
Regards
Reza
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- Stefan Kottwitz
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
Re: Center Part Headings in ToC
welcome to the board!
It depends on the document class you are using. Which one is it?
Stefan
Re: Center Part Headings in ToC
Thank you for your reply. Much appreciated.
I am using \documentclass[12pt,a4paper]{report}
Regards,
Reza
- Stefan Kottwitz
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
Center Part Headings in ToC
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}
Re: Center Part Headings in ToC
Magic. It is working. Thank you so much.
Regards,
Reza