# Left-justified text forced to the right

I am creating a letterhead or other heading to be used at the top of invoices and the like and am having an issue with the spacing of one element:

\documentclass[12pt]{article}
\usepackage{changepage}
\setlength{\parindent}{0pt}

\begin{document}

\begin{center}
\Large \bfseries My Name
\end{center}

\hrulefill

\begin{minipage}[t]{0.5\textwidth}
My street \\
And my city, zip
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
\raggedleft
(my) phone-number \\
my@email.com
\end{minipage}

\vspace{0.5in}

\begin{minipage}[t]{0.5\textwidth}
\textbf{To:}
The Person \\
His street \\
His city, zip
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
\textbf{Date:}

\hspace*{1em}\today
\end{minipage}

\end{document}


I would like the "Date" block to be aligned to the right of the page similarly to the phone and email block above it. My first stab at a solution was to add \raggedleft and some spacing adjustment to the last minipage:

\begin{minipage}[t]{0.5\textwidth}
\raggedleft
\textbf{Date:}\phantom{\today}\hspace*{-1.4em}

\hspace*{1em}\today
\end{minipage}


This almost works: unfortunately, I can't devise a way to make sure the horizontal distance between the start of "Date:" and the start of "January..." is exactly 1em, as I was able to specify in the "To" block.

The idea I have in my head for the solution involves something like this:

\hfill % or \hspace{\fill}: which is preferred here?
\begin{minipage}[t]{\the-exact-width-of-the-date-block}
Date:

\hspace*{1em}\today
\end{minipage}


But, I can't come up with a way to have TeX calculate that width for me--perhaps some sort of multi-line box that can be forced to the left?

I'd set the blocks in separate tabulars:

\documentclass{article}
\setlength{\parindent}{0pt}

\begin{document}

\begin{center}
\Large \bfseries My Name
\end{center}

\hrulefill

\begin{tabular}[t]{@{}l}
My street \\
And my city, zip
\end{tabular}
\hfill
\begin{tabular}[t]{r@{}}
(my) phone-number \\
my@email.com
\end{tabular}

\vspace{0.5in}

\begin{tabular}[t]{@{\hspace{1em}}l}
\hspace{-1em}\textbf{To:} \\
The Person \\
His street \\
His city, zip
\end{tabular}
\hfill
\begin{tabular}[t]{@{\hspace{1em}}l@{}}
\hspace{-1em}\textbf{Date:} \\
\today
\end{tabular}

\end{document}

• Ahh, I see that my HTML experience is bleeding through--I never would have thought to use tables for (gasp) layout! Accepted. – Scott Colby Jan 22 '15 at 8:13
• @Scott: I've made a small correction in terms of the right-hand block tabular spacing. See the edit revision... – Werner Jan 22 '15 at 8:18

You can simply use varwidth from the same package instead of minipage. The varwidth environment is similar to minipage, but its width is determined by its contents.

So you can simply load the package varwidth, substitute minipage with varwidth and add \hfill between consecutive varwidths.

MWE

\documentclass[12pt]{article}
\usepackage{changepage,varwidth}
\setlength{\parindent}{0pt}

\begin{document}

\begin{center}
\Large \bfseries My Name
\end{center}

\hrulefill

\begin{varwidth}[t]{0.5\textwidth}
My street \\
And my city, zip
\end{varwidth}\hfill
\begin{varwidth}[t]{0.5\textwidth}
\raggedleft
(my) phone-number \\
my@email.com
\end{varwidth}

\vspace{0.5in}

\begin{varwidth}[t]{0.5\textwidth}
\textbf{To:}
The Person \\
His street \\
His city, zip