5

In order to get a diagonal line in a cell, I picked up a piece of code from Diagonal lines in table cell

The code adapted to my situation works fine until I decide to use multirow.

Here is the MWE.

\documentclass{article}

\usepackage{multirow}

\usepackage{tikz}
\newcommand\diag[4]{%
  \multicolumn{1}{p{#2}|}{\hskip-\tabcolsep
  $\vcenter{\begin{tikzpicture}[baseline=0,anchor=south west,inner sep=#1]
  \path[use as bounding box] (0,0) rectangle (#2+2\tabcolsep,\baselineskip);
  \node[minimum width={#2+2\tabcolsep},minimum height=\baselineskip+\extrarowheight] (box) {};
  \draw (box.north west) -- (box.south east);
  \node[anchor=south west] at (box.south west) {#3};
  \node[anchor=north east] at (box.north east) {#4};
 \end{tikzpicture}}$\hskip-\tabcolsep}}

\begin{document}

  \begin{tabular}[t]{|c|c|c|}
    \hline
    \multirow{2}{*}{\diag{.1em}{.5cm}{$a$}{$i$}}&\multicolumn{2}{c|}{A}\\\cline{2-2}
    &1\\
  \end{tabular}


\end{document}

This produces an error message,

 ! Misplaced \omit. \multispan ->\omit 
                    \@multispan  l.20 ...ultirow{2}{*}{\diag{.1em}{.5cm}{$a$}{$i$}}
                                                   &\multicolumn{2}{c|}{A}\\\...

If I omit the \multirow part this works fine.

Moriambar
  • 11,466
Masroor
  • 17,842

1 Answers1

4

enter image description here

As noted in comments you can't use \multicolumn here however as it is only spanning 1 cell, you don't need \multicolum and can simply use a \parbox.

The picture was generating a 12pt overfull box warning as 2\tabcolsep was accounted for twice so I removed the inner addition of this ammount.

The A was in a multicolumn{2} so I put the 1 in to match, otherwise things didn't line up.

The code needed array package adding as you'd used \extrarowheight which is defined by that package.

\documentclass{article}

\usepackage{multirow,array}

\usepackage{tikz}
\newcommand\diag[4]{%
%  \multicolumn{1}{p{#2}|}
  \parbox[t]{#2}%
  {\hskip-\tabcolsep
  $\vcenter{\begin{tikzpicture}[baseline=0,anchor=south west,inner sep=#1]
  \path[use as bounding box] (0,0) rectangle (#2,\baselineskip);
  \node[minimum width={#2+2\tabcolsep},minimum height=\baselineskip+\extrarowheight] (box) {};
  \draw (box.north west) -- (box.south east);
  \node[anchor=south west] at (box.south west) {#3};
  \node[anchor=north east] at (box.north east) {#4};
 \end{tikzpicture}}$\hskip-\tabcolsep}}

\begin{document}

  \begin{tabular}[t]{|c|c|c|}
    \hline
    \multirow{2}{*}{\diag{.1em}{.5cm}{$a$}{$i$}}&\multicolumn{2}{c|}{A}\\\cline{2-3}
    &\multicolumn{2}{c|}{1}\\
  \end{tabular}


\end{document}
David Carlisle
  • 757,742