[Tex/LaTex] Right align inside header

fancyhdrheader-footerhorizontal alignment

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}
\usepackage{fancyheadings}

\pagestyle{fancy}
\rhead{\textsc{Tutorial\\The periodic table}}
\lhead{\textsc{My city\\University of somewhere}}
\cfoot{\thepage}

\begin{document}
    hello
\end{document}

Best Answer

You can box the contents of the widest element and use this to width-adjust the shorter one:

enter image description here

\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 right-aligned in a \makebox of width \wd\myheadbox (width of \myheadbox).