5

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:}
  \begin{adjustwidth}{1em}{}
    The Person \\
    His street \\
    His city, zip
  \end{adjustwidth}
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
  \textbf{Date:}

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

\end{document}

First attempt

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}

Second attempt--almost there!

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?

5

I'd set the blocks in separate tabulars:

enter image description here

\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
4

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:}
  \begin{adjustwidth}{1em}{}
    The Person \\
    His street \\
    His city, zip
  \end{adjustwidth}
\end{varwidth}\hfill
\begin{varwidth}[t]{0.5\textwidth}
  \textbf{Date:}

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

\end{document} 

Output

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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