4

I am trying to re-create the letter format using just regular LaTex commands since the letter packages do not give me the desired effect.

In a standard US letter, my (the sender) address would be on the right side of the page, while every line of my address should be flush on the left end. I am wondering how I can achieve this?

Example:

Office 123
Some building
Some company that has a long name
Some city
some zip 12345
Some country

I want the right end of the longest line of my address block, ``Some company that has a long name'' to align with the right edge of the body text of my letter, and at the same time, all lines within my block are flush left.

Any idea how I can do that in LaTex? Thanks!

--- follow up ---

\documentclass[10pt]{article}

%this is for setting up text fonts, pick one and comment out all others
%\usepackage{charter}
\usepackage{kpfonts}
%\usepackage{Times}
\usepackage{graphicx}
%\usepackage{showframe}
\usepackage{calc}
\usepackage{pbox}
% Text layout
\topmargin -2.0cm
\oddsidemargin 0.2 cm
\evensidemargin 0.4cm
\textwidth 15.5cm
\textheight 25cm
\setlength{\parindent}{0pt}

\begin{document}
\thispagestyle{empty}
\begin{minipage}[t]{\textwidth}
\includegraphics[width=3.5cm]{Olympics.jpg}

\hfill
\begin{tabular}{@{}l@{}}
Office 123 \\
Some building \\
Some company that has a long name\\
Some city, some zip 12345 \\
Some country
\end{tabular}

\end{minipage}
\end{document}
2

1 Answer 1

4

There are many ways … two of them:

(Instead of \hfill you can also use {\raggedright <stuff>}.)

Code

\documentclass{article}
\usepackage{showframe}
\usepackage{calc} % for \widthof, can be done without, too (see parbox)
\begin{document}
\hfill

\begin{minipage}{\widthof{Some company that has a long name}}
Office 123 \\
Some building \\
Some company that has a long name \\
Some city, some zip 12345 \\
Some country
\end{minipage}

\hfill
\begin{tabular}{@{}l@{}}
Office 123 \\
Some building \\
Some company that has a long name\\
Some city, some zip 12345 \\
Some country
\end{tabular}

\hfill
\sbox0{Some company that has a long name}% without calc
\parbox{\wd0}{% similar to minipage/not pictured
Office 123 \\
Some building \\
Some company that has a long name\\
Some city, some zip 12345 \\
Some country
}
\end{document}

Output

enter image description here

Update

The \hrulefill should be substituted with \hfill. It's only there to show the baseline.

Code

\documentclass[10pt]{article}
\usepackage[demo]{graphicx}
\usepackage{calc}
% Text layout
\topmargin -2.0cm
\oddsidemargin 0.2 cm
\evensidemargin 0.4cm
\textwidth 15.5cm
\textheight 25cm
\setlength{\parindent}{0pt}

\begin{document}
\thispagestyle{empty}
\includegraphics[width=3.5cm]{Olympics.jpg}
\hrulefill
\begin{tabular}[b]{@{}l@{}}
Office 123 \\
Some building \\
Some company that has a long name\\
Some city, some zip 12345 \\
Some country
\end{tabular}
\end{document}

Output

enter image description here

6
  • Thanks Qrrbrbirlbel! They both work! I have some additional questions, they both are floating bodies, so is there a way of prevent them from drifting to another page or switch vertical order with other similar text-blocks? (e.g. it would be undesirable to have the recipient's address floating above that of the sender). Nov 14, 2012 at 22:32
  • @XianruiCheng Floating? They are not floating. Can you make a MWE that shows that? Nov 14, 2012 at 22:34
  • I am sorry I just started using this forum and i don't quite know how to post stuff properly here... Nov 14, 2012 at 22:50
  • I updated my original post to include that example where the logo (Olympics.jpg) floats above the address block, whereas the desired effect is to have the image aligned left and address aligned right...i apologize for misleading you earlier, your solution is working perfectly, I just brought in an additional related formatting question.... Nov 14, 2012 at 22:58
  • @XianruiCheng You have inserted a blank line between the graphics and the \hfill, this makes a new paragraph, remove it. tabular takes also an optional parameter (b, t and default c) to align the whole tabular. Nov 15, 2012 at 0:00

You must log in to answer this question.

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