GeneralCentering multicolumn headings

LaTeX specific issues not fitting into one of the other forums of this category.
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Centering multicolumn headings

Post by Juanjo »

I have recently had to face a problem similar to that posed by Trikes120. So I revised this old thread and looked at the tabularew package and the (bad) code I posted above time ago. Of course, the tabularew package developped by diegos solves the problem in an automatical form. Anyway, for those who can't or don't want to load tabularew, I provide a new, simple approach for the tables appearing in the last posts. I also use tabularew just for comparison purposes:

Code: Select all

\documentclass{article} 
\usepackage{booktabs,array,tabularew}
\begin{document}   
   
% New column type for being used in the tabularew environment
\newcolumntype{w}{>{\spew{.5}{+1}}}

% New column type for being used in the usual tabular environment
\newcolumntype{R}[1]{>{\hfill}p{#1}}

% Test tables

\begin{tabularew}{@{}llwr@{\,$\pm$\,}lwr@{\,$\pm$\,}l@{}}
   \toprule
   & & \multicolumn{2}{c}{\parbox{2.6cm}{\centering Beer \\ Solids Content}}
     & \multicolumn{2}{c}{\parbox{2.6cm}{\centering Stillage \\ Solids Content}} \\ 
   \cmidrule(l){3-6}
   \multicolumn{2}{l}{Treatment}
      & \multicolumn{2}{c}{\%}
      & \multicolumn{2}{c}{\%} \\ \midrule
   30\% & Conventional &  11.7 & 0.5 a &  18.4 & 1.2 g \\
        & Vacuum &  16.6 & 1.4 b &  20.9 & 1.0 h \\ \bottomrule
\end{tabularew}
   
\bigskip

\begin{tabular}{@{}llR{10.35mm}@{\,$\pm$\,}lR{11.38mm}@{\,$\pm$\,}l@{}} 
   \toprule
   & & \multicolumn{2}{c}{\parbox{2.6cm}{\centering Beer \\ Solids Content}}
     & \multicolumn{2}{c}{\parbox{2.6cm}{\centering Stillage \\ Solids Content}} \\ 
   \cmidrule(l){3-6}
   \multicolumn{2}{l}{Treatment}
      & \multicolumn{2}{c}{\%}
      & \multicolumn{2}{c}{\%} \\ \midrule
   30\% & Conventional &  11.7 & 0.5 a &  18.4 & 1.2 g \\
        & Vacuum &  16.6 & 1.4 b &  20.9 & 1.0 h \\ \bottomrule
\end{tabular}

\bigskip

\begin{tabularew}{wr@{.}l}
   \hline
   \multicolumn{2}{c}{This is a very long heading} \\
   1&2 \\
   3&45 \\
   --4&1 \\
   14&6 \\ \hline
\end{tabularew}

\bigskip

\begin{tabular}{R{5.8em}@{.}l}
   \hline
   \multicolumn{2}{c}{This is a very long heading} \\
   1&2 \\
   3&45 \\
   --4&1 \\
   14&6 \\ \hline
\end{tabular}

\end{document}
The result is almost identical to that given by tabularew. The price to pay, however, is that the argument of the R descriptor must be determined on a trial and error basis or, more technically, playing with lengths (not shown above). I hope this may help someone.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply