[Tex/LaTex] Make the multicolumns in a row equally sized

multicolumntables

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 '16×8' and '8×8' in the next row. Is it possible to fix that?

Here the image:

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…
my cool table

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

Best Answer

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.

Sample outptu

\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:

Multicol output

\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:

Version 1 with colour

\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 :-) :

Version 2 with colour

\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}
Related Question