56

When combining multirow and multicolumn in the same cell of a table I am getting extra vertical lines:

\documentclass[plain]{article}
\usepackage{multirow}
\pagestyle{empty}

\begin{document}

\begin{tabular}{|l|l|l|l|}\hline
  \multirow{10}{*}{numeric literals} & \multirow{5}{*}{integers} & in decimal & \verb|8743| \\ \cline{3-4}
  & & \multirow{2}{*}{in octal} & \verb|0o7464| \\ \cline{4-4}
  & & & \verb|0O103| \\ \cline{3-4}
  & & \multirow{2}{*}{in hexadecimal} & \verb|0x5A0FF| \\ \cline{4-4}
  & & & \verb|0xE0F2| \\ \cline{2-4}
  & \multirow{5}{*}{fractionals} & \multirow{5}{*}{in decimal} & \verb|140.58| \\ \cline{4-4}
  & & & \verb|8.04e7| \\ \cline{4-4}
  & & & \verb|0.347E+12| \\ \cline{4-4}
  & & & \verb|5.47E-12| \\ \cline{4-4}
  & & & \verb|47e22| \\ \cline{1-4}
  \multicolumn{3}{|l|}{\multirow{3}{*}{char literals}} & \verb|'H'| \\ \cline{4-4}
  & & & \verb|'\n'| \\ \cline{4-4}
  & & & \verb|'\x65'| \\ \cline{1-4}
  \multicolumn{3}{|l|}{\multirow{2}{*}{string literals}} & \verb|"bom dia"| \\ \cline{4-4}
  & & & \verb|"ouro preto\nmg"| \\ \cline{1-4}
\end{tabular}

\end{document}

compiled document

Notice the vertical lines in the char literals and string literals cells (which should span three columns). How can they be avoided?

2 Answers 2

68

You have to use \multicolumn{3}{|l|}{} in the following rows also.

\documentclass[plain]{article}
\usepackage{multirow}
\pagestyle{empty}

\begin{document}

\begin{tabular}{|l|l|l|l|}\hline
  \multirow{10}{*}{numeric literals} & \multirow{5}{*}{integers} & in decimal & \verb|8743| \\ \cline{3-4}
  & & \multirow{2}{*}{in octal} & \verb|0o7464| \\ \cline{4-4}
  & & & \verb|0O103| \\ \cline{3-4}
  & & \multirow{2}{*}{in hexadecimal} & \verb|0x5A0FF| \\ \cline{4-4}
  & & & \verb|0xE0F2| \\ \cline{2-4}
  & \multirow{5}{*}{fractionals} & \multirow{5}{*}{in decimal} & \verb|140.58| \\ \cline{4-4}
  & & & \verb|8.04e7| \\ \cline{4-4}
  & & & \verb|0.347E+12| \\ \cline{4-4}
  & & & \verb|5.47E-12| \\ \cline{4-4}
  & & & \verb|47e22| \\ \cline{1-4}
  \multicolumn{3}{|l|}{\multirow{3}{*}{char literals}} & \verb|'H'| \\ \cline{4-4}
  \multicolumn{3}{|l|}{} & \verb|'\n'| \\ \cline{4-4}          %% here
  \multicolumn{3}{|l|}{} & \verb|'\x65'| \\ \cline{1-4}        %% here
  \multicolumn{3}{|l|}{\multirow{2}{*}{string literals}} & \verb|"bom dia"| \\ \cline{4-4}
  \multicolumn{3}{|l|}{} & \verb|"ouro preto\nmg"| \\ \cline{1-4}          %% here
\end{tabular}

\end{document}

enter image description here

3

You can do that table very easily with the package nicematrix.

In the environment {NiceTabular}, you can merge cells both horizontally and vertically with the built-in command \Block. Then, you have a key hvlines which will draw all the rules excepted in the blocks.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{llll}[hvlines]
  \Block{10-1}{numeric literals} & \Block{5-1}{integers} & in decimal & \verb|8743| \\ 
  & & \Block{2-1}{in octal} & \verb|0o7464| \\ 
  & & & \verb|0O103| \\ 
  & & \Block{2-1}{in hexadecimal} & \verb|0x5A0FF| \\ 
  & & & \verb|0xE0F2| \\ 
  & \Block{5-1}{fractionals} & \Block{5-1}{in decimal} & \verb|140.58| \\ 
  & & & \verb|8.04e7| \\ 
  & & & \verb|0.347E+12| \\ 
  & & & \verb|5.47E-12| \\ 
  & & & \verb|47e22| \\ 
  \Block[l]{3-3}{char literals} & & & \verb|'H'| \\ 
  & & & \verb|'\n'| \\ 
  & & & \verb|'\x65'| \\ 
  \Block[l]{2-3}{string literals} & & & \verb|"bom dia"| \\ 
  & & & \verb|"ouro preto\nmg"| \\ 
\end{NiceTabular}

\end{document}

You need several compilations because nicematrix uses PGF/Tikz nodes.

Output of the above code

You must log in to answer this question.

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