Text FormattingHeader not flushed completely to the right

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Header not flushed completely to the right

Post by svend_tveskaeg »

Hi all.

Consider the following MWE:

Code: Select all

\documentclass{article}

\makeatletter
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >\m@ne
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    {\parindent \z@
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >\m@ne
       \Large\bfseries\hfil\partname~\thepart\hfil
       \par\nobreak
     \fi
     \huge\bfseries\sffamily\raggedleft #2 %%% This is where I change how the headline looks.
     \markboth{}{}\par}%
    \nobreak
    \vskip 3ex
    \@afterheading}
\makeatother

\begin{document}
\part{Some random test in order to get at headline that is longer than the textwidth}
\end{document}
As you can see from the MWE, the last line in the header (here, ``textwidth'') is not flushed completely to the right. (I have not noticed this before, even though I have used this modified \part for some time.)

How do I fix this?

Thank you in advance!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

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

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

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Header not flushed completely to the right

Post by Stefan Kottwitz »

The space after #2 is relevant here - just remove it. At many places a space would be ignored, such as when it just marks the end of a macro name, but it can be relevant white space, such as between words.

Code: Select all

\huge\bfseries\sffamily\raggedleft #2%%% This is where...
Now it's flushed right:
flush-right-heading.png
flush-right-heading.png (10.35 KiB) Viewed 2185 times
Stefan
LaTeX.org admin
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: Header not flushed completely to the right

Post by svend_tveskaeg »

I was (obviously) not aware of this.

Thank you, Stefan!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply