[Tex/LaTex] tabularx: bottom alignment on r or l-columns when X column wraps

tablestabularxvertical alignment

In tabularx, when the X-column wraps on more than one line, l/r/c-columns remains top aligned: MWE:

\begin{tabularx}{5cm}{lXr}
 1 & qwer asdf zxcv qwer asdf zxcv qwer asdf zxcv & 1 \\
 2 & qwer asdf zxcv & 2 
\end{tabularx}

If we redefine the X-column the result is near what I wanted but not at all:

\renewcommand{\tabularxcolumn}[1]{b{#1}}
\begin{tabularx}{5cm}{lXr}
 1 & qwer asdf zxcv qwer asdf zxcv qwer asdf zxcv & 1 \\
 2 & qwer asdf zxcv & 2 
\end{tabularx}

Why redefining \tabularxcolumn to put a paragraph on bottom (or middle) changes to bottom all columns but X-column?

This is not exactly what I want. The first column must be top aligned and the third must be bottom aligned. Like this:

\begin{tabularx}{5cm}{cXr}
 1 & qwer asdf zxcv qwer & \\
   & asdf zxcv qwer asdf & \\
   & zxcv & 1 \\
 2 & qwer asdf zxcv & 2 
\end{tabularx}

Would be even better if the space that X-column lefts on all other columns (in this case two lines on bottom of first column and two lines on top of third column) may be filled, e.g. with a central dot or whatever.

Best Answer

enter image description here

This takes two runs of latex to measure things

\documentclass{article}
\usepackage{tabularx}

\makeatletter
\def\savepos#1{\leavevmode\pdfsavepos\write\@auxout{%
\gdef\noexpand#1{\the\pdflastypos sp }}}

\def\xstart#1{\expandafter\savepos\csname save@start@#1\endcsname}

\def\xend#1{\expandafter\savepos\csname save@end@#1\endcsname}

\def\xpad#1#2#3{%
\vtop{%
\baselineskip\normalbaselineskip
#2%
\expandafter\ifx\csname save@start@#1\endcsname\relax
\else
\dimen@\csname save@start@#1\endcsname\relax
\loop
\ifdim\dimen@>\csname save@end@#1\endcsname
\advance\dimen@-\baselineskip
\hbox{$\cdot$}%
\repeat
\fi
#3%
}}


\def\xleft#1#2{\xpad{#1}{\hbox{#2}}{}}

\def\xright#1#2{\xpad{#1}{}{\hbox{#2}}}





\begin{document}

\begin{tabularx}{5cm}{cXr}
 \xleft{a}{1} & \xstart{a}qwer asdf zxcv qwer 
    asdf zxcv qwer asdf
    zxcv\xend{a} & \xright{a}{1} \\
 \xleft{b}{2} & \xstart{b}qwer asdf zxcv\xend{b} & \xright{b}{2} 
\end{tabularx}

\end{document}
Related Question