[Tex/LaTex] how to right-align on a page a block of multi-lined text which is itself left-aligned within the block

horizontal alignmentletters

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}

Best Answer

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