I need advice on tables in LaTeX. \cline does not work properly.

This:

\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multirow{2}{*}{{A $\wedge$ B}} & \multicolumn{4}{c|}{B}  \\
\hline
& \textbf{P} & \textbf{O} &\textbf{X}& \textbf{N}\\
\hline
\end{tabular}

gives me this:

enter image description here

so when I use \cline to handle it:

\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multirow{2}{*}{{A $\wedge$ B}} & \multicolumn{4}{c|}{B}  \\
\cline{2-6}
& \textbf{P} & \textbf{O} &\textbf{X}& \textbf{N}\\
\hline
\end{tabular}

enter image description here

but the \cline erased some lines. Can anyone help?

  • Try to add \shorthandoff{-} after the \begin{document} command, it looks that divis is an active character (the babel package). – Malipivo Apr 5 '15 at 20:50
  • Hi Michael, welcome to the site! Could you turn your snippet into a complete minimum working example that starts with documentclass? It makes it easier for folks looking at your problem :) – cmhughes Apr 5 '15 at 20:56
  • \shorthand{-} doesnt work for me, ok i ll add it :) – nocturne Apr 5 '15 at 20:58
up vote 4 down vote accepted

You specify six columns in the table preamble, but then you use only five.

When TeX builds the table, since it finds nothing in the last column, it doesn't consider it, so \cline{2-6} finds itself in trouble and the result is what you observe.

Of course, specifying \cline{2-5} works.

\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multirow{2}{*}{{A $\wedge$ B}} & \multicolumn{4}{c|}{B} & \\
\cline{2-6}
& \textbf{P} & \textbf{O} &\textbf{X}& \textbf{N} & \\
\hline
\end{tabular}

\medskip

\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multirow{2}{*}{{A $\wedge$ B}} & \multicolumn{4}{c|}{B}  \\
\cline{2-5}
& \textbf{P} & \textbf{O} &\textbf{X}& \textbf{N}\\
\hline
\end{tabular}
\end{document}

enter image description here

Note that in the first tabular the sixth column has been filled (with nothing printed, but there's the relative &.

If your aim is to produce the following table,

enter image description here

here is the code:

\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multicolumn{2}{|c|}{\multirow{2}{*}{{A $\wedge$ B}}} & \multicolumn{4}{c|}{B} \\
\cline{3-6}
\multicolumn{2}{|c|}{} & \textbf{P} & \textbf{O} &\textbf{X}& \textbf{N} \\
\hline
\multirow{4}{*}{A} & \textbf{P} & P & O & X & N \\
\cline{2-6}
& \textbf{O} & O & O & N & N \\
\cline{2-6}
& \textbf{N} & X & N & X & N \\
\cline{2-6}
& \textbf{N} & N & N & N & N \\
\hline
\end{tabular}
\end{document}

An alternative way, without \multirow:

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{*{5}{c}}
\toprule
\multicolumn{5}{c}{A $\wedge$ B} \\
\midrule
A & \multicolumn{4}{c}{B} \\
\cmidrule(lr){1-1} \cmidrule(lr){2-5}
& \textbf{P} & \textbf{O} &\textbf{X}& \textbf{N} \\
\textbf{P} & P & O & X & N \\
\textbf{O} & O & O & N & N \\
\textbf{N} & X & N & X & N \\
\textbf{N} & N & N & N & N \\
\bottomrule
\end{tabular}
\end{document}

enter image description here

  • because i need exactly this :i59.tinypic.com/2vtyzwx.png so i use 6 columns – nocturne Apr 5 '15 at 21:12
  • @MichaelHalinár Well, your first multirow cell should straddle two columns, not one. – egreg Apr 5 '15 at 21:37
  • well, thats it, thanks :) – nocturne Apr 6 '15 at 6:55

You have 5 columns not 6:

\documentclass{article}
\usepackage{multirow}
\begin{document}

\begin{tabular}{|c|c|c|c|c|}
\hline
\multirow{2}{*}{A $\wedge$ B}  & \multicolumn{4}{c|}{B}  \\
\cline{2-5}
     & \textbf{P} & \textbf{O} & \textbf{X} & \textbf{N} \\
\hline
\end{tabular}    
\end{document}

enter image description here

EDIT

Now try this (if you need exactly the table as per the link in your comment):

\documentclass{article}
\usepackage{multirow}
\begin{document}

\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multicolumn{2}{|c|}{\multirow{2}{*}{A $\wedge$ B}} & \multicolumn{4}{c|}{B}\\
\cline{3-6}
\multicolumn{2}{|c|}{} & \textbf{P} & \textbf{O} &\textbf{X}& \textbf{N}\\
\hline
\multirow{4}{*}{A}& \textbf{P} & P & O & X & N \\ \cline{2-6}
                  & \textbf{O} & O & O & N & N \\ \cline{2-6}
                  & \textbf{N} & X & N & X & N \\ \cline{2-6}
                  & \textbf{N} & N & N & N & N \\ \hline
\end{tabular}

\end{document}

enter image description here

  • but i need 6. column in next row right after this two rows – nocturne Apr 5 '15 at 21:02
  • Where should the sixth column be? Your image in the question shows only 5 columns. – AboAmmar Apr 5 '15 at 21:04
  • because i need exactly this table : i59.tinypic.com/2vtyzwx.png – nocturne Apr 5 '15 at 21:09

I dont know why but this worked

\end{tabular}
\begin{tabular}{|c|c|c|c|c|c}
\hline
\cline{6-6}   %this added \cline
\multirow{2}{*}{{A $\wedge$ B}} & \multicolumn{4}{c|}{B}  \\
\cline{2-6}
& \textbf{P} & \textbf{O} &\textbf{X}& \textbf{N}\\
\hline
\end{tabular}

enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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