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}

Peter Grill
  • 223,288

4 Answers4

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

karlkoeller
  • 124,410
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].

Werner
  • 603,163
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}} :-) 
David Carlisle
  • 757,742
  • 2
    But this solution also aligns first column a to the bottom. – Ignasi Mar 21 '14 at 08: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:-) – David Carlisle Mar 21 '14 at 09: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}? – Peter Grill Mar 21 '14 at 09: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 – David Carlisle Mar 21 '14 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. – Peter Grill Mar 21 '14 at 15:15
  • @PeterGrill If the tex solution doesn't fit with your mental model you need to change the latter not the former:-) Every table row has a single baseline running through it and the question is where do you want each cell relative to that baseline. If you say XXX is on the baseline that's the default so you need the bottom row of the X column to be on teh baseline which is a b column. Or yo say teh baseline goes through the top row of the X column (as in my revised answer) then you need to move XXX off that baseline. – David Carlisle Mar 21 '14 at 16:03
  • :-) Yes, I WILL submit to the TeX model of thinking. :-) I think I will go with the minipage solution, so please post a bit of code in the answer as well. – Peter Grill Mar 21 '14 at 16:12
  • I@PeterGrill f I post the minipage version, where would you like the [b] argument:-) – David Carlisle Mar 21 '14 at 16:30
  • @PeterGrill answer updated again – David Carlisle Mar 21 '14 at 16:34
  • FYI, I am accepting this answer as the minipage solution defers the codding to the tabular specification and does not need tweaking on a per cell basis. Some of my lines are not the full length of the column and they align the way I want with this solution. – Peter Grill Mar 22 '14 at 22:07
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

F. Pantigny
  • 40,250