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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10397
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: 10397
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