3

I would like to merge some cells horizontally in an "interlocked" manner, but LaTeX does not let me do that when all relevant cells are filled with characters of roughly equal length.

Code:

\documentclass{article}

\begin{document}
\begin{tabular}{|c|c|c|c|c|}
\hline
A & 1 & \multicolumn{2}{c|}{2} \\ \hline
B & \multicolumn{2}{c|}{2} & 1 \\ 
\hline
\end{tabular}

\end{document}

1 Answer 1

4

The problem is that you have some columns with no entries, in which case Tex "optimises the column away".

If you has a row with all cells, the \multicolumn work as expected. If you really want no full rows, you can add a "hidden" row as in the second table.

\documentclass{article}

\begin{document}
\begin{tabular}{|c|c|c|c|c|}
\hline
A & 1 & \multicolumn{2}{c|}{2} & \\ \hline
B & \multicolumn{2}{c|}{2} & 1 & \\
\hline
a&b&c&d&e\\
\hline
\end{tabular}


\bigskip


\begin{tabular}{|c|c|c|c|c|}
\hline
A & 1 & \multicolumn{2}{c|}{2} & \\ \hline
B & \multicolumn{2}{c|}{2} & 1 & \\
\hline
\omit&&&&
\end{tabular}

\end{document}

enter image description here

2
  • Thanks! That is really cool. Is there something that limits how many & symbols you can put after \omit ? Apr 18, 2017 at 6:16
  • @Rethliopuks the \omit only applies to the first cell, normally latex adds a strut there so all the table rows have the same height, adding a row in this form adds a zero-height row, the number of & is just one less than the number of columns as specified in the \begin{tabular} Apr 18, 2017 at 6:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .