1

Questions like alignment-in-longtable are quite common. One of the possible solutions is use of the multirow cells, where with the option t or b the contents of the cells are aligned to the top or bottom of the cell. The problem here is to set the number of lines of text in the adjacent cells. It can be determined by manual counting of rows, however its automatic count is preferable.

An elegant solution was shown @David Carlisle in edit to my answer on the aforementioned question, where he show use of the endgraf macro. This solution work fine, however, I notice a bit annoying problem: it also insert empty row in the cell:

\documentclass{scrbook}
\usepackage{multirow, xltabular}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage{lipsum}

\begin{document}
    \begin{xltabular}{\linewidth}{@{} l|L<{\endgraf\xdef\zzz{\the\prevgraf}}@{}c @{}}
Column 1 & Column 2     & Column 3                      \\  \hline
top      &  \lipsum[1]  & \multirow[b]{\zzz}{*}{bottom} \\  \hline
top      & \lipsum[11]  & \multirow[b]{\zzz}{*}{bottom} \\  \hline
    \end{xltabular}
\end{document}

enter image description here

Is there a way to remove this vertical space?

0

1 Answer 1

2

At the end of an X cell (which is p in disguise) LaTeX inserts a \strut. In your case this happens after a paragraph has been formed.

You can remove the blank line so created by adding a negative vertical space.

\documentclass{scrbook}
\usepackage{multirow, xltabular}
\usepackage{lipsum}

\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcommand{\countlines}[1]{%
  \vspace{-\normalbaselineskip}\strut
  \endgraf
  \xdef#1{\the\prevgraf}%
}

\begin{document}

\begin{xltabular}{\linewidth}{@{} l|L<{\countlines{\zzz}}@{}c @{}}
Column 1 & Column 2    & Column 3                      \\  \hline
top      & \lipsum[1]  & \multirow[b]{\zzz}{*}{bottom} \\  \hline
top      & \lipsum[11] & \multirow[b]{\zzz}{*}{bottom} \\  \hline
\end{xltabular}

\end{document}

enter image description here

1
  • Thank you for solution! (+1)
    – Zarko
    Jan 25, 2021 at 14:32

You must log in to answer this question.

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