6

I would like to put an address in my document as follows:

|                             |
|                     Name    |
|                     Street #|
|                     City    |
|                     ZIP     |
|                             |

where the | mark the left and right page borders. I would like the items of the address (Name, Street etc.) to be left-flushed, but the box right-flushed so that the longest item touches the right page border.

Is there a simple way to accomplish this?

3 Answers 3

5

Use a tabular for the left alignment and use \hfill to flush it to the right.

\documentclass{article} 
\begin{document}

Before

\null\hfill\begin{tabular}{l@{}}
     Name \\
     Street \# \\
     City \\
     ZIP \\
 \end{tabular}

\noindent\hrule% Show width of line
After

\end{document}
4
  • why do you have \null?
    – user2478
    Commented Mar 15, 2011 at 18:57
  • @Herbert: You are right, it works without it. Sometimes it happened to me that the fill macros didn't work when there wasn't a \hbox{} or shorter \null at one side, so I just got used to adding them. Commented Mar 15, 2011 at 19:27
  • It should be pointed out that this does not work if there is no empty line between Before and \hfill.
    – mschilli
    Commented Oct 15, 2013 at 9:00
  • @tparker The @{} removes the intercolumn space before and after the column. In this particular case the first instance is superfluous, which is why Martin left it out, but the second is not. If you remove it, the table will no longer be flush with the right margin.
    – Alan Munn
    Commented May 18, 2018 at 3:08
0
\documentclass{scrartcl}
\usepackage{tikz}

\begin{document}

\hfill \tikz
\node [align=left]{name\\Town\\ code postal};
\end{document}
0
\newlength{\abc}

\begin{flushright}\settowidth{\abc}{River Street}
\parbox{\abc}{\noindent
Tom Robinson\\
River Street\\
Pittsburgh\\
123456}
\end{flushright}

You must log in to answer this question.

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