1

I am trying to use this solution which uses tikz, however I cannot get it to compile properly. I get the error:

Misplaced \omit. ...llcolor[HTML]{EFEFEF}\diag{0.2em}{1cm}{a}{b}

Searching for that led me to this other question, but as far as I can tell it is not related since \diag does not have an optional argument.

What is causing the error/how can I prevent it from happening?

Apologies for the lengthy preamble, but since I'm at a complete loss, I want to ensure that this MWE uses the exact same packages and settings as I do in my actual document.

(Pseudo)MWE

\PassOptionsToPackage{table,cxdraw}{xcolor}

\documentclass[draft]{book}
\usepackage[numbers,sort&compress]{natbib}
\usepackage[protrusion=true,expansion,babel=true]{microtype}
\usepackage{mathtools} % This includes "amsmath" and the dcases environment among other things
\usepackage{dsfont}
\usepackage{tikz}
\usepackage[ngerman,english]{babel}
% For tables:
\newcolumntype{x}{@{\hskip\tabcolsep\vrule width 1pt\hskip\tabcolsep}}
\usepackage{booktabs}
\usepackage{multirow}
% For listings and source code
%\usepackage{algorithm2e}
\usepackage{listings}
\lstset{%
    basicstyle=\footnotesize,
    showstringspaces=false,
    numbers=left,
    numberstyle=\tiny,
    stepnumber=1,
    captionpos=b,
    language=Java,
    frame=lines
}
%% ---------------- end of usepackages -------------------------

\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-\pgflinewidth},
            minimum  height=\baselineskip+\extrarowheight-\pgflinewidth] (box) {};
            \draw[line cap=round] (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
    }
}
\newcommand{\e}[1]{\ensuremath{\left\langle#1\right\rangle}}
%%----------------- end of preamble ----------------------------
\begin{document}
\begin{tabular}{@{}
        >{\columncolor[HTML]{EFEFEF}}c 
        >{\columncolor[HTML]{EFEFEF}}c
        >{\columncolor[HTML]{EFEFEF}}c
    xcccc@{}}
    $\kappa(0)$ & $\kappa(0)$ & \cellcolor[HTML]{EFEFEF}\diag{0.2em}{1cm}{a}{b} & \cellcolor[HTML]{EFEFEF}$i\mod{p} = 0$    & \cellcolor[HTML]{EFEFEF}$i\mod{p}=1$    & \cellcolor[HTML]{EFEFEF}$i\mod{p}=3$  & \cellcolor[HTML]{EFEFEF}$i\mod{p}=3$ \\
    0           & 0           & 2                                                                               & $\e{0}\e{1}$                  & $\e{1}\e{0}$                          & -                                     & -                         \\
    0           & 1           &                                                                                 &                               &                                       &                                       &                           \\
    1           & 0           & \multirow{-2}{*}{3}                                                             & \multirow{-2}{*}{$\e{0}\e{1}$}& \multirow{-2}{*}{$\e{1}\e{\kappa(1)}$}& \multirow{-2}{*}{$\e{\kappa(1)}\e{0}$}& \multirow{-2}{*}{-}       \\
    1           & 1           & 4                                                                               & $\e{01}$                      & $\e{1}\e{1}$                          & $\e{1}\e{0}$                          & $\e{0}\e{0}$           
\end{tabular}
\end{document}
5
  • As given, does not compile. ! Package array Error: Illegal pream-token ("): 'c' used. -- will try again after minimizing the code. May 26, 2015 at 13:12
  • @MikeRenfro Thanks for your effort. I find that weird, since it has been defined by \newcolumntype{"}{@{\hskip\tabcolsep\vrule width 1pt\hskip\tabcolsep}} in the preamble...
    – MaxAxeHax
    May 26, 2015 at 13:23
  • Alternatively, you can omit the \diag command entirely and use the diagbox package. May 26, 2015 at 13:23
  • Have you tried using another character instead of "? It is probably clashing with the ngerman option of babel which makes it an active letter (like ~), maybe even english or babel itself. May 26, 2015 at 13:49
  • On my system, the symbol doesn't cause problems. I'm going to change it however, although I don't know exactly what active letters are - and the standard column types (l,r,c) seem to be "active letters" too...
    – MaxAxeHax
    May 26, 2015 at 14:00

1 Answer 1

1

\cellcolor should be inside the final argument to \multicolumn; you can do

\newcommand\diag[5]{%
    \multicolumn{1}{p{#2}|}{%
        #5%
        \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-\pgflinewidth},
            minimum  height=\baselineskip+\extrarowheight-\pgflinewidth] (box) {};
            \draw[line cap=round] (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
    }
}

and call

\diag{0.2em}{1cm}{a}{b}{\cellcolor[HTML]{EFEFEF}}

The result I get is horrible, but it's the same if I remove the coloring.

1
  • Yes, it works even though as you say, the result looks pretty bad. I did some further reading and found a way to avoid diagonal cells at all, and typeset the table elegantly. Thanks for your effort, I'll get back to this and try to learn what wasn't working when I'm done with the actual work.
    – MaxAxeHax
    May 26, 2015 at 15:00

You must log in to answer this question.

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