# Different column number in rows

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}

• You need to actually create 7 columns and then make appropriate spans. – WillAdams Nov 8 '13 at 19:09
• The only solution I've found is using a table with the minimum common multiple of the columns. In this case it would be a 13 columns table, and then merge columns. – jlanza Nov 8 '13 at 19:09
• Do you have a MWE that we can look at? – azetina Nov 8 '13 at 19:15
• To get the columns to have equal width, try doing this with tabularx; cf. this question. – alexis Nov 8 '13 at 19:34

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

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

• Not only a beautiful solution, but also one minimalizing (formal) number of colums. – Przemysław Scherwentke Nov 8 '13 at 20:24

To vertically center the H2 cell, you will need to also use the multirow package.

\documentclass[a4paper]{article}
\usepackage{multirow}
\begin{document}

\begin{tabular}{ c c c c c }
H1 & \multicolumn{4}{c}{\multirow{2}{*}{H2}} \\
T1 \\
T1 & test & \multicolumn{2}{c}{text} & text \\
T1 & \multicolumn{2}{c}{text} & \multicolumn{2}{c}{text} \\
T1 & text & text & text & text \\
\end{tabular}


This code will produce:

To make the row with 3 text's have evenly sized tables, I assumed 13 cells would be required. However, the sizing was still unusual until I added a row of blank cells to the bottom.

\begin{tabular}{ c c c c c c c c c c c c c }
H1 & \multicolumn{12}{c}{\multirow{2}{*}{H2}} \\
T1 \\
T1 & \multicolumn{4}{c}{text} & \multicolumn{4}{c}{text} & \multicolumn{4}{c}{text} \\
T1 & \multicolumn{6}{c}{text} & \multicolumn{6}{c}{text} \\
T1 & \multicolumn{3}{c}{text} & \multicolumn{3}{c}{text} & \multicolumn{3}{c}{text} & \multicolumn{3}{c}{text} \\
& & & & & & & & & & & & \\
\end{tabular}


This produces:

• I reached the same solution and have the same problem, as you can see for the MWE I just put – jlanza Nov 8 '13 at 19:25
• Ah, yes. You must have posted that while I was editing. – SnoringFrog Nov 8 '13 at 19:33

There were a few wrong \multicolumn commands in your code.

Hope this is what you wanted

Code:

\documentclass{article}
\usepackage{multirow,booktabs}

\begin{document}
\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{2}{c}{gggggggg} & \multicolumn{2}{c}{ddddddddd} & \multicolumn{4}{c}{ggggggggg} & \multicolumn{4}{c}{dsdsdsds}  \\
$I=\gamma \cdot x$ & \multicolumn{2}{c}{(6)} & \multicolumn{2}{c}{(5)} & \multicolumn{4}{c}{(3)} & \multicolumn{4}{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}
\end{document}