4

I'm typesetting a formal letter within a much larger document (hundreds of pages). I'd like to produce something along the lines of what you get with the letter document class, but without actually that class. (I'm heavily invested in memoir already.)

The main thing I'm struggling with is the address. The requirement is that the address box float all the way right, but be left-aligned within the box.

The best I've achieved is this hack:

\hspace*{0.6\linewidth}
\begin{minipage}{0.4\linewidth}
Joe Bloggs\\
123 ABC Street\\
Townville, Regionia\\
Countrystan\\
Friday, May 29, 2015
\end{minipage}

but the results are unsatisfactory.

How do I float this address right but have it aligned flush left?

1

2 Answers 2

4

Put the address inside a tabular and use \hfill to shove it over to the right:

enter image description here

\documentclass{memoir}
\usepackage{showframe}% Just for this example
\begin{document}

\hfill
\begin{tabular}{l@{}}
  Joe Bloggs \\
  123 ABC Street \\
  Townville, Regionia \\
  Countrystan \\
  Friday, May 29, 2015
\end{tabular}

\end{document}

The column gap was removed on the right of the left-aligned column using @{}. There's no need to remove it on the left as the content is filled from the left margin anyway.

1
  • I hope you don't mind that I've used your code from this solution only to compare the outputs of two methods in a single image. I am still new on TeX.SX and don't know if I should've asked for your permission to use your code before posting my answer. Hope that's fine with you.
    – Amar
    Commented May 30, 2015 at 7:24
1

This method is based on \parbox[pos][height][contentpos]{width}{text}. A new length variable \lnglen is declared and its value is set to the width of the longest line in your input text (which is the last line showing date) using \settowidth macro. Now, we can use this length variable to set the width of \parbox in order to make it exactly as wide as the input text, so that it won't leave any trailing space when flushed to right edge using \hfill.

To show you the exact width of the output, I've added a \vrule at the left edge of parbox and just for the sake of better comparison, I've included @werner's solution at the top with a vrule as well.

Code:

\documentclass{memoir}
\usepackage{showframe} % Just for this example
\newlength{\lnglen} % defines a new custom length variable
\settowidth{\lnglen}{Friday, May 29, 2015} % sets variable value to longest line's width
\begin{document}
%
%%%%%% by @werner %%%%%%
\hfill
\vrule               % added by @amar
\begin{tabular}{l@{}}
  Joe Bloggs \\
  123 ABC Street \\
  Townville, Regionia \\
  Countrystan \\
  Friday, May 29, 2015
\end{tabular}
%%%%%% by @werner %%%%%%
%
\vspace*{0.2in}
\hrule
\vspace*{0.2in}
%
%%%%%% by @amar %%%%%%
\hfill % flushes everything to right
\vrule
\parbox[c][][s]{\lnglen}{% sets \parbox of \lnglen width!
  Joe Bloggs \\
  123 ABC Street \\
  Townville, Regionia \\
  Countrystan \\
  Friday, May 29, 2015
}%
%%%%%% by @amar %%%%%%
%
\end{document}

Output:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .