I have a header, prepared using fancyhdr. I would like the first row of the left header to be right-aligned with the second row of the left header. In the following MWE I would like "My City" to be right aligned with "University of somewhere" (so that "City" is just above "somewhere"). How do I achieve that?

\documentclass{article}
\usepackage{fancyhdr}

\pagestyle{fancy}
\cfoot{\thepage}

\begin{document}
hello
\end{document}


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

\pagestyle{fancy}
\cfoot{\thepage}

\begin{document}
hello
\end{document}​


\myheadbox contains the "University of somewhere" (in the appropriate font, \scshape). Then, "My city" is right-aligned in a \makebox of width \wd\myheadbox (width of \myheadbox).

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
\scshape
\begin{tabular}[t]{@{}r@{}}
Tutorial\\The periodic table
\end{tabular}}
\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}
\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}