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.

In response to my earlier question the following working code has been provided:

\documentclass{article}
\usepackage{showframe}

\begin{document}
\hfill
\begin{tabular}{l@{}}
 some text\\
 some other text
\end{tabular}
\end{document}

My initial attempt was similar, but used the flushleft environment instead of tabular.

\documentclass{article}
\usepackage{showframe}

\begin{document}
\hfill
\begin{flushleft}
 some text\\
 some other text
\end{flushleft}
\end{document}

The difference between the two approaches is that in the former one \hfill before the environment causes the text to stick to the right side of the page. In the latter one the text is still on the left side.

So, I wonder what fundamental difference between tabular and flushleft (I guess, between their implementations) causes this difference in behaviour.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

The \flushleft environment creates a paragraph with the lines that are aligned with the left-hand margin, which is exactly what you get:

enter image description here

TeX works in boxes, and the \hfill has no box to apply the fill to so that it gets pushed to the right.

If you place the flushleft environment within a varwidth then you would obtain the results you desire:

enter image description here

\documentclass{article}
\usepackage{showframe}
\usepackage{varwidth}

\begin{document}
\hfill
\begin{varwidth}{\linewidth}
\begin{flushleft}
 some text\\
 some other text
\end{flushleft}
\end{varwidth}
\end{document}
share|improve this answer
add comment

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.