Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using \markright to create a page heading. I'm having trouble centering some text in this heading, and I'd like to know how to do this.

Here's my current setup:

\documentclass{article}

\newcommand{\TitleString}{This Is The Title}

\begin{document}

\pagestyle{myheadings}

\markright{\TitleString \hfill Matt Groff \hfill}

Title and copyright are above.

\end{document}

I use \hfill to fill in the space so that my name is close to centered, but for large titles it's way off. Is there a way to fix this? I'd like my name to be completely centered.

share|improve this question

5 Answers 5

up vote 2 down vote accepted

Here's a simplified variant of Geoffrey's solution that avoids \protect and the doubling of \TitleString:

\documentclass{article}

\newcommand{\TitleString}{This Is A Rather Long Title}

\begin{document}

\pagestyle{myheadings}

\markright{\rlap{\TitleString}\hfill Matt Groff\hfill}

Title and copyright are above.

\end{document}

(Note that there are no spaces before the \hfill!)

Explanation: \rlap writes the text but just "overlaps it to the right" without it taking up any space.

share|improve this answer

Use \phantom to "balance" your title line, like this:

\documentclass{article}
\usepackage[pass,showframe]{geometry}  % <-- help to see what's going on

\newcommand{\TitleString}{This Is A Rather Long Title}

\begin{document}

\pagestyle{myheadings}

\markright{\TitleString \hfill%
            Matt Groff%
            \hfill\protect\phantom{\TitleString}}

Title and copyright are above.

\end{document}
share|improve this answer
    
Excellent! By the way, do you know why it puts everything in italics (or emphasis)? –  Matt Groff Nov 8 '10 at 1:05
3  
@Matt Groff: sure - if you look in the definitions of the oneside and twoside header macros in article.cls (\ps@headings), you'll see that it applies \slshape to the header output stream (this sometimes maps to \itshape in some font families). All you need do to modify your header formatting is to change your invocation of \markright, e.g., to \markright{\textnormal{\TitleString ... }}. –  Geoffrey Jones Nov 8 '10 at 2:38
1  
@Matt: Note the % after your name in Geoffrey's solution. This is important since otherwise there'll be an unwanted space after the name, and it won't be exactly centered. –  Hendrik Vogt Nov 8 '10 at 13:09

My usual choice would be the fancyhdr package:

\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{This is a title}
\chead{Mark Groff}
\renewcommand*\headrulewidth{0.0 pt}
\begin{document}
Hello world
\end{document}
share|improve this answer

Use the scrpage2 package which is part of KOMA-Script.

\documentclass{article}

\newcommand*{\TitleString}{This Is The Title}

\usepackage[automark]{scrpage2}
\pagestyle{scrheadings}
\ihead{\TitleString}% Inner head 
\chead{Matt Groff}

\begin{document}

Title and copyright are above.

\end{document}
share|improve this answer
    
That'll do it. Thanks! I'm surprised that it requires a package, for something so simple. –  Matt Groff Nov 7 '10 at 23:54
2  
The LaTeX2e kernel is well known for being rather inflexible on formatting, I'm afraid. –  Joseph Wright Nov 8 '10 at 5:52

Obligatory ConTeXt solution:

\setupheadertexts[Mark Groff]     % Center
\setupheadertexts[\TitleString][] % Left  Right
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.