4

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.

  • With b you change the X column to be bottom-aligned which it is. The vertical alignment of the c and r column aren’t changed at all (they are only one line anyway). Or in other words: There is only one baseline. – Qrrbrbirlbel Apr 28 '13 at 16:22
  • My question was not clear... What I want is to change the vertical alignment of the c, r and l columns when the X column is longer than one line. Now I understand what I asked about the behaviour of \tabularxcolumn, but this does not solves my problem... I want the text of the first column be written on the first line when the X-column wraps, and the text of the third column aligned to the last line, like the last code, but automatically wrapped instead of doing it manually. – Emilio Lazo Apr 28 '13 at 19:38
4

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}
| improve this answer | |
  • What I wanted. Thanks for your useful code! \hfill inside \hbox -like inside other dynamic boxes- has no effect. I do have \hfill inside some cells within a column. I must rewrite that in other way or add one extra column to isolate these two components of some cells that appears one on the left and one on the right on the same cell. – Emilio Lazo May 2 '13 at 0:15
  • Now I want to use again this solution but I have two issues, which are in essence the same: the use of \hbox. The \cdot is drawn horizontally aligned to the first character on previous/next line, so it is now centered even on 'c' column (the first column). Changing "1" or "2" to something longer on first and third columns magnifies this effect... And, \hfill inside \hbox expands to nothing, I would like to have something like a \hfill b on one cell on the third column, and would be better if the \cdot appears centered (on both first and third column). What to do? – Emilio Lazo Feb 20 '16 at 7:59
  • @EmilioLazo the site doesn't really work well if you ask a new question 2 years later, in comments. Ask a new question (you can reference this one) – David Carlisle Feb 20 '16 at 10:42
  • done. Is at <tex.stackexchange.com/questions/295003/…> Nobody answered yet. – Emilio Lazo Feb 23 '16 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.