2

I have a table that looks like this:

\documentclass[12pt,a4paper]{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{rl}
\multicolumn{2}{c}{heading} \\
\toprule
string & much longer string long  \\
string & much longer string long  \\
string & much longer string long  \\
string & much longer string long  \\
\end{tabular}
\end{document}

"heading" looks like it is a heading only of the second column. I would like it to be centered over the split between both columns so that it is clear that this is not the case. Alternative opinions about how to typeset this are also welcome

1 Answer 1

3

The space between two columns usually consists of the right \tabcolsep of the first column and the left \tabcolsep of the second column. The first column is already right-aligned, \rlap prints to the right, \kern\tabcolsep moves to the place between the two columns and \makebox[0pt] centers the text without occupying space for TeX.

\documentclass[12pt,a4paper]{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{rl}
  \rlap{\kern\tabcolsep\makebox[0pt]{heading}} \\
  % variant:
  % \rlap{\makebox[2\tabcolsep]{heading}} \\
\toprule
string & much longer string long  \\
string & much longer string long  \\
string & much longer string long  \\
string & much longer string long  \\
\end{tabular}
\end{document}

Result

Alternative:

  • Depending on the circumstances, the table might not need a "heading", because it can be put into the table caption.
1
  • No idea how you did it, but it works beautifully. I will consider the alternative too!
    – sup
    Jun 27, 2015 at 15:58

You must log in to answer this question.

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