2

I have been trying to right align the \part in latex, but without any success

Please also take into account the TOC input and the text formatting (fonts, etc. from the whole document). Basically I don't wanna change anything else in the basic part declaration of latex, except right justifying it and use a ":" or "-" instead of the "." at the end of the Part number.

I would also like the page number to be hidden.

Thank you guys!

PS: Unfortunately I can't post a picture of what I have right now.

I have found this code while searching the web:

\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
  \refstepcounter{part}%
  %  add to TOC, but without page number (since this page is not counted)
   \addtocontents{toc}{\protect
      \nonumcontentsline{\numberline{\partname\space\thepart}#1}}
\else
  %  add to TOC, but without page number
  \addtocontents{toc}{\protect\nonumcontentsline{#1}}
\fi
\markboth{}{}%
{\centering
 \interlinepenalty \@M
 \normalfont
 \ifnum \c@secnumdepth >-2\relax
   % part number - UPPERCASE, and make it slightly larger
   \large \bfseries \MakeUppercase{\partname\nobreakspace\thepart}
   \par
   \vskip 20\p@
 \fi
 % part title - make it slightly larger
 \large \bfseries #2\par}%
\@endpart}

But whatever I do, I can't right align it. Tried the flushright environment. My other idea was to put it in a makebox to be aligned.. But that's not possible :(

UPDATE

Using the minipage environment, I was able to right align the \part :-D yuhuu

I have just put the \part inside the minipage environment and played a bit its attributes. It works fine. But the remaining problem is how to get the part number and the title on the same line:

Part I: Title of the first part

1
  • 1
    Haven't you forgotten to add your code? To remove the page number try this command \pagestyle{empty}, or this command if you want to remove the number only on one page \thispagestyle{empty}
    – Ludovic C.
    Commented Jun 19, 2013 at 12:46

1 Answer 1

2

Using \raggedleft is sufficient.

\documentclass{book}

\makeatletter
\def\@part[#1]#2{%
  \ifnum \c@secnumdepth >-2\relax
    \refstepcounter{part}%
    %  add to TOC, but without page number (since this page is not counted)
    \addtocontents{toc}{\protect
      \nonumcontentsline{\numberline{\partname\space\thepart}#1}}%
  \else
    %  add to TOC, but without page number
    \addtocontents{toc}{\protect\nonumcontentsline{#1}}%
  \fi
  \markboth{}{}%
  {\raggedleft
   \interlinepenalty \@M
   \normalfont\large\bfseries % <-- Adjust here
   \ifnum \c@secnumdepth >-2\relax
     \large\bfseries\partname\nobreakspace\thepart: %
   \fi
   #2\par}%
  \thispagestyle{empty}% <-- remove the page number
  \@endpart}
\makeatother

\begin{document}
\mainmatter
\part{Title of the first part}
\end{document}

If \large\bfseries is not what you want, change it to suit.

2
  • Thank egreg for the suggestion. However, how can i have the part name, number and title on the same line? thanks
    – candidson
    Commented Jun 20, 2013 at 8:45
  • @pro They are on the same line.
    – egreg
    Commented Jun 20, 2013 at 8:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .