# Make the multicolumns in a row equally sized?

I have some big tables and I want to know how it is possible to make the columns in a row all equally sized. You can see in the row 'Intra Prediciton' that the column with the content 'I_PCM' is bigger than the others in its row. Same with '16x8' and '8x8' in the next row. Is it possible to fix that?

Here the image:

I also appreciate other suggestions how to improve the tables.

heres the mess ...

    \newcolumntype{Y}{>{\columncolor[gray]{.8} } c|}
\newcolumntype{N}{>{\columncolor[gray]{.8} \color{gray}}  c|}

%Spaltenzahl 8
% \color{gray} \color{lightgray} %\rowcolor{hellgrau} \cellcolor{dunkelgrau}
\begin{tabular}{|       >{\color{white}  \columncolor[gray]{.2}[.5\tabcolsep]}      c       |       >{\columncolor[gray]{.8}[.5\tabcolsep]}     c        |      >{\columncolor[gray]{.8}[.5\tabcolsep]}     c       |       >{ \columncolor[gray]{.8}[.5\tabcolsep]}        c   |       >{ \columncolor[gray]{.8}[.5\tabcolsep]}        c   |       >{ \columncolor[gray]{.8}[.5\tabcolsep]}        c       |   >{ \columncolor[gray]{.8}[.5\tabcolsep]}        c   |   >{ \columncolor[gray]{.8}[.5\tabcolsep]}        c    }
\hline
Bildverfahren                                                   &           \multicolumn{3}{Y}{progressive}     &  \multicolumn{3}{Y} {interlaced } \\
\hline
Frames/Slices                                                   &       \multicolumn{2}{Y}{I}       &       \multicolumn{2}{Y}{P}       &   \multicolumn{2}{Y}{B}       \\
\hline
Slices                                                                             & \multicolumn{3}{N}{nein}   &  \multicolumn{3}{Y}{ja}  \\
\hline
Transformation                                              & \multicolumn{2}{N}{8x8 DCT}       & \multicolumn{2}{Y}{8x8 IDCT} & \multicolumn{2}{Y}{4x4 IDCT} \\
\hline
Adaptive Quantization                   & \multicolumn{2}{N}{nein} & \multicolumn{2}{N}{Lumi} & \multicolumn{2}{Y}{Variance} \\
\hline
Max. Ref Frames                                         & \multicolumn{3}{N} {keine} & \multicolumn{3}{Y}{16} \\
\hline
B-Pyramid                                                               &\multicolumn{3}{N} {nein} & \multicolumn{3}{Y} {ja} \\
\hline
Loop-Filter                                                                 & \multicolumn{3}{N} {nein} & \multicolumn{3}{Y} {ja} \\
\hline
Entropiekodierung                                   & \multicolumn{3}{Y} {CAVLC} &  \multicolumn{3}{Y}{CABAC} \\
\hline
SubPixel ME                                                         &  \multicolumn{2}{N} {nein} & \multicolumn{2}{N} {halb} &  \multicolumn{2}{Y}{viertel} \\
\hline
Intra Prediction                                                & \multicolumn{1}{N} {nein} & \multicolumn{1}{Y}{16x16} & \multicolumn{1}{Y}{8x8} &  \multicolumn{1}{Y}{4x4}  &\multicolumn{2}{Y}{ I\_PCM}\\
\hline
MB-Partitionierung                                  & \multicolumn{1}{Y}{16 x 16} & \multicolumn{1}{Y}{8x16} & \multicolumn{2}{Y}{16x8} & \multicolumn{2}{Y}{8x8} \\
\hline
SubMB-Partitionierung                   & \multicolumn{1}{N}{nein} & \multicolumn{1}{Y}{8x8} & \multicolumn{1}{Y}{4x8} & \multicolumn{1}{Y}{8x4} & \multicolumn{2}{Y}{4x4} \\
\hline
%Intra Prediction & \color{gray} nein  & 16×16 & 8×8 &  4×4  \\
Farb-Sampling                                                   &           \multicolumn{2}{Y}{4:0:0}       & \multicolumn{2}{Y}{4:2:0} &  \multicolumn{1}{Y}{4:2:2} &  \multicolumn{1}{Y}{4:4:4} \\
\hline
Bit-Tiefe                                                                       & \multicolumn{1}{Y}{8}  & \multicolumn{2}{Y}{8 bis 10} & \multicolumn{2}{Y}{8 bis 12} & \multicolumn{1}{Y}{8 bis 14} \\
\hline
Error Prevention /Handling  &  \multicolumn{3}{N} {nein} &\multicolumn{3}{Y}{ja} \\
\hline
Level/Profile                                                       &  \multicolumn{3}{N} {nein} &\multicolumn{3}{Y}{ja} \\
\hline
\end{tabular}


EDIT:

Isn't that cool? Used tablet now...

Unfortunately the vrules are sometimes not so beautiful. You see it when comparing the last two lines. Should I color the table?

-
without any source shown we can not really help, but in general if you use p{2cm} rather than c as the column type then you can control the column widths exactly. – David Carlisle Feb 9 '13 at 13:45
You will need to provide some code. The table also has some parts that appear structurally wrong. What is the relation of the 'nein' and 'ja'cells to "P"? – Yiannis Lazarides Feb 9 '13 at 20:03
@DavidCarlisle, it seems OP wants centered columns of the same width. Moreover, the table shows some columns-and-a-half or so entries. I'm sure I could cobble up something with p{xxx}, assorted \multicolumn{} and centering text in the column. But I shudder at the mess that will result. – vonbrand Feb 10 '13 at 0:37
with all respect this table is just terrible. Different contrasts, wrong column sperators vertical lines that don't divide for human readers etc. Just scratch that and make a readable one. – percusse Feb 10 '13 at 0:57
you dont think it looks nicely? awww.... – user1234567890 Feb 15 '13 at 10:12

Even though I don't like the layout you are trying to produce, since I think it is very confusing for the reader, here is some coding that will produce equally spaced cells in a particular column.

\documentclass{article}

\usepackage{array}
\newcommand{\tabelt}[1]{\hfil\hbox to 0pt{\hss #1 \hss}\hfil}

\begin{document}

\begin{tabular}{|c|@{}>{\hbox to 9cm\bgroup}{c}<{\egroup}@{}|}
\hline
x and z&\tabelt{A}\vrule\tabelt{XX}\vrule\tabelt{ZZZ}\strut\\
\hline
yy or pp&\tabelt{BBB}\vrule\tabelt{C}\vrule\tabelt{DD}\vrule\tabelt{P}\strut\\
\hline
\end{tabular}

\end{document}


If the row has a non-standard height, then the final \strut will have to be replaced by an appropriate version of \vrule width 0pt height 14pt depth 4pt.

The basic idea of the code is that \tabelt produces a variable width box with its contents centered, but of zero width. To make the first and last boxes correct, the table specification includes @{} to kill spacing added between columns. To prevent everything collapsing the width of the column is specified.

A similar idea will work in \multicolumn:

\documentclass{article}

\usepackage{array}
\newcommand{\tabelt}[1]{\hfil\hbox to 0pt{\hss #1 \hss}\hfil}

\begin{document}

\begin{tabular}{|c|c|c|c|}
\hline
First line & Some interesting random column text & and more & and more\\
\hline
Second line&\multicolumn{3}{>{\unskip}{c}<{}@{}|}{\tabelt{BBB}\vrule\tabelt{C}\vrule\tabelt{DD}\vrule\tabelt{P}}\\
\hline
\end{tabular}

\end{document}


Here will kill extra spacing at the beginning with \unksip and the \strut is no longer necessary.

## Update: Usage with colortbl

The first solution works with colortbl with very little modification:

\documentclass{article}

\usepackage{array,colortbl,xcolor}
\newcommand{\tabelt}[1]{\hfil\hbox to 0pt{\hss #1 \hss}\hfil}

\begin{document}

\begin{tabular}{|>{\columncolor{red}\color{white}}c|%
@{}>{\columncolor{green}[0pt][0pt]%
\hbox to 9cm\bgroup\color[gray]{0.7}}{c}<{\egroup}@{}|}
\hline
x and z&\tabelt{A}\vrule\tabelt{\color{black}XX}\vrule\tabelt{ZZZ}\strut\\
\hline
yy or pp&\tabelt{\color{black}BBB}\vrule\tabelt{C}%
\vrule\tabelt{DD}\vrule\tabelt{P}\strut\\
\hline
\end{tabular}

\end{document}


For the second version, using \multicolumn, one has adjust the code some what, since colortbl produces its alignments uses fills instead of fils (in attempt to stop the user doing what we are trying to do :-) :

\documentclass{article}

\usepackage{array,colortbl,xcolor}

\newcommand{\tabelt}[1]{\hfill\hbox to 0pt{\hss #1 \hss}\hfill}

\begin{document}

\showoutput
\begin{tabular}{|>{\columncolor{red} \color{white}}c|%
>{\columncolor{green}}c|%
>{\columncolor{green}}c|%
>{\columncolor{green}}c|%
}
\hline
First line & Some interesting random column text & and more & and more\\
\hline
Second line&\multicolumn{3}{>{\unkern\unskip%
\columncolor{green}[0.5em][24em]\color[gray]{0.7}}{c}<{}|}%
{\tabelt{BBB}\vrule\tabelt{C}\vrule\tabelt{\color{black}DD}\vrule\tabelt{P}}\\
\hline
\end{tabular}

\end{document}

-
thank you. The first solution is working, but the in the second solution the content of the for columns with the characters (b,c,d,p) in the second line are all colapsed in the center. Why is that? – user1234567890 Feb 17 '13 at 8:16
You need to make sure the columns you are spanning have non-zero (actually sufficiently large) width. This is done in two different ways in my examples. Alternatively you can force entries to have some minimum width by redefining \tabelt with the 0pt replaced by a non-zero width, e.g.\newcommand{\tabelt}[1]{\hfil\hbox to 5em{\hss #1 \hss}\hfil} – Andrew Swann Feb 17 '13 at 9:21
\usepackage{colortbl} - the trouble maker. I removed it from my document and now the second example works also for me. Thanks. – user1234567890 Feb 17 '13 at 10:32
puhh... seems that I need this package though. Do you know how to fix that, or an alternative? – user1234567890 Feb 17 '13 at 11:55
See my update for use with colortbl. – Andrew Swann Feb 17 '13 at 14:21