Right align inside header
Don't load fancyheadings
, which is the obsolete version of fancyhdr
.
The easiest way is to use tabular
which will take care of the alignment:
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear all fields
\fancyhead[R]{%
\scshape
\begin{tabular}[t]{@{}r@{}}
Tutorial\\The periodic table
\end{tabular}}
\fancyhead[L]{%
\scshape
\begin{tabular}[t]{@{}r@{}}
My city\\University of somewhere
\end{tabular}}
\fancyfoot[C]{\thepage}
Set the \headheight
to the value that fancyhdr
will show you in the .log file. For a 10pt document it says to do
\setlength{\headheight}{24pt}
You may typeset the left header \raggedleft
inside a minipage
with a width of the widest element (calculated with the help of \widthof
, which is provided by the calc
package).
\documentclass{article}
\usepackage{fancyhdr}
\usepackage{calc}
\pagestyle{fancy}
\rhead{\textsc{Tutorial\\The periodic table}}
\lhead{%
\begin{minipage}[b]{\widthof{\textsc{University of somewhere}}}
\raggedleft
\textsc{My city\\University of somewhere}%
\end{minipage}
}
\cfoot{\thepage}
\begin{document}
hello
\end{document}
EDIT: As pointed out by egreg in chat, one may replace the minipage
with a varwidth
environment "whose resulting width is the natural width of its contents" (package manual).
\documentclass{article}
\usepackage{fancyhdr}
\usepackage{varwidth}
\pagestyle{fancy}
\rhead{\textsc{Tutorial\\The periodic table}}
\lhead{%
\begin{varwidth}[b]{10cm}
\raggedleft
\textsc{My city\\University of somewhere}%
\end{varwidth}
}
\cfoot{\thepage}
\begin{document}
hello
\end{document}
Output for both examples:
You can box the contents of the widest element and use this to width-adjust the shorter one:
\documentclass{article}
\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
\newsavebox{\myheadbox}% Heading storage box
\pagestyle{fancy}
\rhead{\textsc{Tutorial\\The periodic table}}
\lhead{\textsc{\savebox{\myheadbox}{University of somewhere}\makebox[\wd\myheadbox][r]{My city}\\\usebox{\myheadbox}}}
\cfoot{\thepage}
\begin{document}
hello
\end{document}
\myheadbox
contains the "University of somewhere" (in the appropriate font, \scshape
). Then, "My city" is r
ight-aligned in a \makebox
of width \wd\myheadbox
(width of \myheadbox
).