# Table: Can I shift a column by half the height of a row?

This question is best explained by giving the usecase:

I have a table where I list some data and I would like to add a column to the right which gives the ratio of two adjacent rows. Now to make it more obvious the ratio of which rows this is I would like to shift the column which the ratios by half the height of a row so that each of the ratio values sits to the right of the two columns which it was calculated from.

 A    ratio
------------
3      2
6      3
18


imagine the same table but the numbers in the right column shifted down by half a row.

Is this even possible?

\documentclass[a4paper]{article}
\usepackage{collcell,array}
\newcommand{\shiftdown}[1]{\smash{\raisebox{-.5\normalbaselineskip}{#1}}}
\newcolumntype{C}{>{\collectcell\shiftdown}c<{\endcollectcell}}
\begin{document}
\begin{tabular}{cC}
A & \multicolumn{1}{c}{ratio}\\
\hline
3 &2\\
6 &3\\
18
\end{tabular}
\end{document}


The \multicolumn{1}{c}{...} is necessary to avoid applying the shift also to the heading.

• (+1) Snap! And thanks for showing how to use \normalbaselineskip -- I was sure there was a command like that but couldn't remember what it was...
– Ant
Commented Sep 26, 2011 at 10:57
• Using a dimensione expressed in ex units is quite the same. Commented Sep 26, 2011 at 11:00
\documentclass[a4paper]{article}
\usepackage{booktabs}
\usepackage{collcell}
\newcommand*{\movedown}[1]{%
\smash{\raisebox{-1ex}{#1}}}
\newcolumntype{q}{>{\collectcell\movedown}r<{\endcollectcell}}
% (for "quotient")
\begin{document}
\begin{tabular}{rq}
\toprule
A & \multicolumn{1}{l}{ratio}\\
\midrule
3 & 2\\
6 & 3\\
18 \\
\bottomrule
\end{tabular}
\end{document}


The key part here is that \raisebox moves the number down and \smash stops it from just expanding the row (as far as the table is concerned the number takes up no space at all). Then we apply it to the whole column at once using Martin Scharrer's collcell (which loads array behind the scenes), and use \multicolumn to stop the column title from going awry.

Using booktabs is just to make it look prettier.

(I'll also note that there are probably better ways to code the shift distance than hard-coding it as -1ex!)