我正在尝试使用这解决方案使用tikz
,但我无法正确编译。我收到错误:
Misplaced \omit. ...llcolor[HTML]{EFEFEF}\diag{0.2em}{1cm}{a}{b}
为了寻找这个,我另一个问题,但据我所知,它是不相关的,因为\diag
没有可选参数。
什么原因导致了错误/我该如何防止它发生?
抱歉,序言太长了,但由于我完全不知所措,我想确保这个 MWE 使用与我在实际文档中使用的完全相同的包和设置。
(伪)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}
答案1
\cellcolor
应该在最后一个参数里面\multicolumn
;你可以这样做
\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
}
}
并调用
\diag{0.2em}{1cm}{a}{b}{\cellcolor[HTML]{EFEFEF}}
我得到的结果很糟糕,但如果我去除颜色,结果还是一样。