Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
I don't know much about the letter class but you can additionally try to use Koma-Script's scrlttr2 class which gives you great customization. — Related/duplicate: How to flush right but align left? –  Qrrbrbirlbel Nov 14 '12 at 22:38
    
You can use a \Longstack[l]{} for the left-aligned material (stackengine package). –  Steven B. Segletes Jan 31 at 17:53

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer
    
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). –  Xianrui Cheng Nov 14 '12 at 22:32
    
@XianruiCheng Floating? They are not floating. Can you make a MWE that shows that? –  Qrrbrbirlbel Nov 14 '12 at 22:34
    
I am sorry I just started using this forum and i don't quite know how to post stuff properly here... –  Xianrui Cheng Nov 14 '12 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.... –  Xianrui Cheng Nov 14 '12 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. –  Qrrbrbirlbel Nov 15 '12 at 0:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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