# Table cell (or other paragraph) first line left aligned, subsequent lines right aligned

I’d like table cells to have automatic line breaking, but the first line should be on the left side of the cell and subsequent lines aligned to the right side of the cell, as if the first line were \raggedright and subsequent lines were \raggedleft.

One of my Glisterings columns in TUGboat, 28-2, 2007 (https://tug.org/TUGboat/tb28-2/tb89glister.pdf) discusses over 8 different unusual paragraph shapes, among which is \raggedlefthenright that provides the layout you are after.

% paraprob.tex  SE 593461
\documentclass[twocolumn]{article}
\usepackage{lipsum}
\newcommand*{\raggedrightthenleft}{%
\leftskip   =0pt plus 1fill
\rightskip  =0pt plus 1fil
\parfillskip=0pt
\everypar{\hskip 0pt plus -1fill\relax}%
\parindent=0pt\relax}

\begin{document}
\setlength{\parskip}{\baselineskip}

\raggedrightthenleft

This paragraph is set following a \verb!\raggedrightthenleft!
declaration. It looks strange to me but there you go.

This paragraph follows the identical declaration. \lipsum[1]

Note that some lines in the previous paragraph are fully justified because
they are just the right length to fill the textwidth.

\end{document}


• Thanks for the somewhat more comprehensive answer! It does look strange in a paragraph of prose, but in the context I’m using it, in table cells with Bible references, I think it looks better than any alternative.
– dpk
Apr 19 '21 at 9:00

Using a trick from the gmverse source, we can define our own tabularx column type:

\newcolumntype{U}{>{%
\leftskip=0pt plus 1fill%
\rightskip=0pt plus 1fil%
\arraybackslash%
\hskip 0pt plus -1fill\relax{}}X}


Example:

\begin{tabularx}{0.8\linewidth}{r | U}
1 & \blindtext \\
2 & \blindtext \\
\end{tabularx}


The same trick with leftskip and rightskip (note the use of fill vs fil!) can be used to define other environments and commands with similar behaviour.