[Tex/LaTex] Different column number in rows

multicolumntables

I would like to create a table like this:

| H1   |           h2           | <--- is centered vertically
| T1   |                        |
| T1   |   text  | text  | text |
| T1   |   text     |      text |
| T1   | text |text | text|text |

How can I do so? mainly the problem is with row 2.

Working example but not centering correctly the row with 5 columns

\begin{table}[!hbt]
   \centering
   \caption{caption} \label{tab:table} 
   \begin{tabular}{c c c c c c c c c c c c c}
      \toprule
      xxxxxxx & \multicolumn{12}{c}{yyyyyyyyyyyyyy} \\
      \midrule
      aaaaaaa & \multicolumn{12}{c}{\multirow{2}{*}{bbbbbbbbbbbbbb}} \\
      $E=\lambda \cdot x$ & \multicolumn{12}{c}{} \\
      \midrule
      cccccccc & \multicolumn{4}{c}{ddddddddddddddddddd} & \multicolumn{4}{c}{eeeeeeeeeeeeeeeee} & \multicolumn{4}{c}{fffffffffffffff} \\
      $P=\beta \cdot x$ & \multicolumn{4}{c}{(4)} & \multicolumn{4}{c}{(3)} & \multicolumn{4}{c}{(1)}\\
      gggggggggg & \multicolumn{3}{c}{gggggggg} & \multicolumn{3}{c}{ddddddddd} & \multicolumn{3}{c}{ggggggggg} & \multicolumn{3}{c}{dsdsdsds}  \\
      $I=\gamma \cdot x$ & \multicolumn{3}{c}{(6)} & \multicolumn{3}{c}{(5)} & \multicolumn{3}{c}{(3)} & \multicolumn{3}{c}{(1)} \\
      Calidad canal & \multicolumn{4}{c}{aaaaaaaaaaaa} & \multicolumn{4}{c}{hhhhhhhhhhhhhhhhhhhhhh} & \multicolumn{4}{c}{rrrrrrrrrrrrrrrr} \\
      $\Delta = \delta \cdot x$ & \multicolumn{4}{c}{(5)} & \multicolumn{4}{c}{(3)} & \multicolumn{4}{c}{(1)} \\
      \bottomrule
   \end{tabular}
\end{table}

Best Answer

The following provides a much cleaner interface, if you're interested in spreading out the contents beyond column 1 evenly:

enter image description here

\documentclass{article}
\usepackage{booktabs,multirow,tabularx}% http://ctan.org/pkg/{booktabs,multirow,tabularx}
\newcommand{\makecell}[2][@{}c@{}]{\begin{tabular}{#1}#2\end{tabular}}
\usepackage[margin=1in]{geometry}% Just for this example
\setlength{\parindent}{0pt}% Just for this example
\begin{document}

\begin{tabularx}{\linewidth}{c X}
  \toprule
  xxxxxxx & 
    \hfill yyyyyyyyyyyyyy \hfill\null \\
  \midrule
  \makecell{aaaaaaa \\ $E = \lambda \cdot x$} & 
    \hfill bbbbbbbbbbbbbb \hfill\null \\
  \midrule
  \makecell{cccccccc \\ $P = \beta \cdot x$} & 
    \hfill \makecell{ddddddddddddddddddd \\ (4)} 
    \hfill \makecell{eeeeeeeeeeeeeeeee \\ (3)} 
    \hfill \makecell{fffffffffffffff \\ (1)} \hfill\null \\
  \makecell{gggggggggg \\ $I = \gamma \cdot x$} & 
    \hfill \makecell{gggggggg \\ (6)} 
    \hfill \makecell{ddddddddd \\ (5)} 
    \hfill \makecell{ggggggggg \\ (3)} 
    \hfill \makecell{dsdsdsds \\ (1)} \hfill\null \\
  \makecell{Calidad canal \\ $\Delta = \delta \cdot x$} & 
    \hfill \makecell{aaaaaaaaaaaa \\ (5)} 
    \hfill \makecell{hhhhhhhhhhhhhhhhhhhhhh \\ (3)} 
    \hfill \makecell{rrrrrrrrrrrrrrrr \\ (1)} \hfill\null \\
  \bottomrule
\end{tabularx}

\end{document}

The entire structure is set in a tabularx consisting of two columns. The second X-column removes the guesswork of trying to figure out how many columns to use and how wide the table should be. \hfills spread the content evenly within the column, while \makecell (similar in definition to that provided by the makecell package) stacks elements vertically.

The above code is clean and allows customization by changing the definition of \makecell (if needed).

Related Question