Graphics, Figures & TablesTable cells lose formatting after multicolumn

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
greybadger
Posts: 13
Joined: Fri Aug 21, 2009 2:36 pm

Table cells lose formatting after multicolumn

Post by greybadger »

Hi,

I have a problem whereby individual cells following a multicolumn statement are not centred. The following is a simple example:

Code: Select all

\begin{table}[h]
\begin{center}
\begin{tabular}{|c|cc|cc|cc|}
\hline
Heading & \multicolumn{2}{|c|}{2 Column Heading} & \multicolumn{2}{|c|}{2 Column Heading} & \multicolumn{2}{|c|}{2 Column Heading}\\
A & B & C & D & E & F & G\\
\hline
a & b & c & d & e & f & g\\
\hline
\end{tabular}
\end{center}
\end{table}
In this table, all letters that are not A and aligned left. Can anyone shed any light on this?

Thanks!

Recommended reading 2024:

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

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

User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Table cells lose formatting after multicolumn

Post by Stefan Kottwitz »

The content of those cells is actually centered, have a look at this modified example, where some entries are wider:

Code: Select all

\begin{tabular}{|c|cc|cc|cc|}
\hline
Heading & \multicolumn{2}{|c|}{2 Column Heading} & \multicolumn{2}{|c|}{2 Column Heading} & \multicolumn{2}{|c|}{2 Column Heading}\\
A & B & C & D & E & F & G\\
\hline
a & bbbbbb & cccccc & d & e & f & g\\
\hline
\end{tabular}
Stefan
LaTeX.org admin
greybadger
Posts: 13
Joined: Fri Aug 21, 2009 2:36 pm

Re: Table cells lose formatting after multicolumn

Post by greybadger »

Ah yes, OK... I'll rephrase my question then :)

In the above example, the columns following a multicolumn statement aren't of equal width (the first of the merged columns is small, the second is wide). Is there a way to force these to be of equal width?

Each of my cell entries is just a number between 0 and 10 with 2 decimal places, so it looks odd having misaligned columns.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Table cells lose formatting after multicolumn

Post by Stefan Kottwitz »

You could use a p column with fixed width, like this:

Code: Select all

\usepackage{array}
\newcolumntype{x}{>{\centering\arraybackslash}p{1.5cm}}
...
\begin{tabular}{|c|xx|xx|xx|}
...
Stefan
LaTeX.org admin
greybadger
Posts: 13
Joined: Fri Aug 21, 2009 2:36 pm

Re: Table cells lose formatting after multicolumn

Post by greybadger »

Great, works fine. Thanks.
Post Reply