10

How do I get the last column text to be at the bottom of the row?

enter image description here

That is I want the XXX to be aligned with the line containing the arrow.

I tried playing around with \multirow{3}{-3ex}{XXX}, but obviously I don't understand \multirow.

Code:

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{multirow}

\begin{document}
    \begin{tabularx}{\linewidth}[t]{l X p{1.3cm}}
        & Header & Title \\\cmidrule(lr){2-2}\cmidrule(lr){3-3}
        a. & Some text text text text text text text text text text text text text text 
            text text text text text text text text text text 
            Want XXX on this line $\rightarrow$%
         & XXX\\
    \end{tabularx}
\end{document}
5
  • Is this answer helpful?
    – Adam Liter
    Commented Mar 21, 2014 at 5:53
  • @Adam: Yep, very useful, but surprisingly different answers than here. Commented Mar 21, 2014 at 7:23
  • Oh I just saw the link Adam gave is same as answer I just posted. Probably close this as dup? Commented Mar 21, 2014 at 8:31
  • I don't think it's a duplicate. OP wants two different vertical alignments in same row.
    – Ignasi
    Commented Mar 21, 2014 at 8:40
  • @Ignasi OK new answer posted:-) Commented Mar 21, 2014 at 10:25

4 Answers 4

4

(Edited answer, using different mechanism)

enter image description here

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}

\makeatletter
\def\foo#1{\leavevmode
\expandafter\ifx\csname PDFSAVE#1\endcsname\relax
\expandafter\gdef\csname PDFSAVE#1\endcsname{0sp}%
\fi
\pdfsavepos\write\@auxout{\gdef\string\PDFSAVE#1{\the\pdflastypos}}}
\makeatother
\begin{document}
    \noindent
    \begin{tabularx}{\linewidth}[t]{l X p{1.3cm}}
        & Header & Title \\\cmidrule(lr){2-2}\cmidrule(lr){3-3}
        a. & \foo{a}Some text text text text text text text text text text text text text text 
            text text text text text text text text text text 
            Want XXX on this line $\rightarrow$\foo{b}%
         & \smash{\raisebox{\dimexpr\PDFSAVEb sp-\PDFSAVEa sp\relax}{XXX}}\\
    \end{tabularx}
\end{document}

The original answer moved the baseline of the X column to the bottom using

\renewcommand\tabularxcolumn[1]{b{#1}}

But that affects all X columns, and also makes the a. align on the bottom row. The latter problem could be fixed by moving the a. into the second column (with a hanging indent)

If you only want to change the alignment of some X columns in a table, then you can use:

>{\begin{minipage}[b]{\hsize}}X<{\end{minipage}} :-) 
10
  • 2
    But this solution also aligns first column a to the bottom.
    – Ignasi
    Commented Mar 21, 2014 at 8:35
  • Yes or rather it doesn't move the 1st and 3rd columns down all, it moves the 2nd column up. (the a. could be moved to the start of the paragraph in the X column, where it belongs:-) Commented Mar 21, 2014 at 9:14
  • @DavidCarlisle: But what if it was not part of the 2nd column? I don't really like your \parbox solution at the other answer. Can't you have two different X column types in the same table: One b{#1} and another t{#1}? Commented Mar 21, 2014 at 9:18
  • You can if you want, yes (or simpler just use minipipage withing the column spec so) >{\begin{minipage}{\hsize}[b]}X<{\end{minipage}} is a one-off b-alignment in an otherwise p (top) aligned table Commented Mar 21, 2014 at 10:01
  • The minipage idea works better with >{\begin{minipage}[b]{\hsize}}X<{\end{minipage}} :-) But it is kind of weird to apply something to column 2, to get the desired positioning in column 3 -- same reason I dislike the \parbox solution in Vertical alignment in tabular cells with variable height. Commented Mar 21, 2014 at 15:15
10

If you want to play with \multirow, you can use the second optional argument, which is the "fixup", a length for fine tuning the position.

In your case it should be -2\baselineskip

MWE:

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{multirow}

\begin{document}
    \noindent
    \begin{tabularx}{\linewidth}[t]{l X p{1.3cm}}
        & Header & Title \\\cmidrule(lr){2-2}\cmidrule(lr){3-3}
        a. & Some text text text text text text text text text text text text text text
            text text text text text text text text text text
            Want XXX on this line $\rightarrow$%
         & \multirow{1}{*}[-2\baselineskip]{XXX}\\
    \end{tabularx}
\end{document} 

Output:

enter image description here

5

Depending on the type of content associated with XXX, the following is an easy way of obtain the bottom-alignment that doesn't require knowledge of the preceding column entries:

enter image description here

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}

\noindent
\begin{tabularx}{\linewidth}[t]{l X p{1.3cm}}
  & Header & Title \\\cmidrule(lr){2-2}\cmidrule(lr){3-3}
  a. & Some text text text text text text text text text text text text text text 
      text text text text text text text text text text 
      Want XXX on this line $\rightarrow$
   & \\[-\normalbaselineskip] && XXX
\end{tabularx}
\end{document}

Idea: Set XXX on its own line, but overlaid with the bottom of the previous line using \\[-\normalbaselineskip].

1

Here is a solution with {NiceTabularX} of nicematrix and its built-in command \Block.

\documentclass{article}
\usepackage{nicematrix}
\usepackage{booktabs}

\begin{document}
\begin{NiceTabularX}{\linewidth}[t]{l X p{1.3cm}}
    & Header & Title \\\cmidrule(lr){2-2}\cmidrule(lr){3-3}
    a. & Some text text text text text text text text text text text text text text 
        text text text text text text text text text text 
        Want XXX on this line $\rightarrow$%
     & \Block[B]{}{XXX \strut} 
\end{NiceTabularX}
\end{document}

You need several compilations (because nicematrix uses PGF/TikZ nodes under the hood).

Output of the above code

1
  • Works great after 3rd run. Commented Oct 31, 2023 at 1:20

You must log in to answer this question.

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