3

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.

1 Answer 1

2

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}

You must log in to answer this question.

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