Text FormattingRagged left Alignment on the right

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
heavytull
Posts: 16
Joined: Wed Feb 08, 2012 9:38 pm

Ragged left Alignment on the right

Post by heavytull »

Hi,
I would like a little portion of my text containing very short lines to be \raggedleft while that portion is positioned so as its longest line touches the right border of the page.
for example:

THE PAGE
_______________________
| TextTextTextTextText |
| TextTextTextTextTextx |
| |
| PortionBegin |
| TextTextTextte | <--Longest line touches the right border
| TextText |
| Text |
| Text |
| PortionEnd |
| |
| TextTextTextTextText |
| TextTextTextTextTextx |
|_______________________ |

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Ragged left Alignment on the right

Post by Stefan Kottwitz »

For positioning blocks of text, \parbox or a minipage environment are useful. However, they require specifying a width.

For simply aligning lines, a tabbing or a tabular environment could be used. For example, a tabular environment just has a natural width, you don't need to know that before. So, here we use
  • a tabular environment
  • a left aligned column
  • @{} for removing the default space before and after the column
  • \hfill to push the table to the right

Code: Select all

\hfill\begin{tabular}{@{}l@{}}
Small\\
portion of\\
text
\end{tabular}
Stefan
LaTeX.org admin
heavytull
Posts: 16
Joined: Wed Feb 08, 2012 9:38 pm

Re: Ragged left Alignment on the right

Post by heavytull »

your solution works fine.
I'm actually replying because I just found that \hfill had no effect after a \\ or \newline. It works only straight after some text of after a \par.
Does anyone know why?
Post Reply