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}
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

| improve this answer | |
  • Thanks! That is really cool. Is there something that limits how many & symbols you can put after \omit ? – Rethliopuks Apr 18 '17 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} – David Carlisle Apr 18 '17 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.