# Difference in behaviour between tabular and flushleft environments

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.

-

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

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:

\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}

-