我正在尝试写一个表格\LaTeX
需要划掉一些单元格并为其添加颜色,以直观地显示主题的进展。我正在使用这篇文章删除表格单元格能够按照我的需要充分跨表格单元格,但当我尝试使用\cellcolor
它时,我无法获得预期的结果。为简单起见,我将再次编写我使用的代码片段,这些代码来自上面的链接:
\documentclass{article}
\usepackage{pgf,tikz,colortbl}
\usetikzlibrary{arrows}
\usetikzlibrary{babel}
\usetikzlibrary{calc}
\usepackage{zref-savepos}
%
%
\newcounter{NoTableEntry}
\renewcommand*{\theNoTableEntry}{NTE-\the\value{NoTableEntry}}
%
\newcommand*{\notableentry}{%
\multicolumn{1}{@{}c@{}|}{%
\stepcounter{NoTableEntry}%
\vadjust pre{\zsavepos{\theNoTableEntry t}}% top
\vadjust{\zsavepos{\theNoTableEntry b}}% bottom
\zsavepos{\theNoTableEntry l}% left
\hspace{0pt plus 1filll}%
\zsavepos{\theNoTableEntry r}% right
\tikz[overlay]{%
\draw[black]
let
\n{llx}={\zposx{\theNoTableEntry l}sp-\zposx{\theNoTableEntry r}sp},
\n{urx}={0},
\n{lly}={\zposy{\theNoTableEntry b}sp-\zposy{\theNoTableEntry r}sp},
\n{ury}={\zposy{\theNoTableEntry t}sp-\zposy{\theNoTableEntry r}sp}
in
(\n{llx}, \n{lly}) -- (\n{urx}, \n{ury})
(\n{llx}, \n{ury}) -- (\n{urx}, \n{lly})
;
}%
}%
}
\begin{document}
\begin{table}
\centering
\caption{Activities.}
\begin{tabular}{|c|c|}
\hline
Activities & \rotatebox[origin=c]{-90}{August 2016} \\
%
\hline Introduction & \notableentry \\
\hline
\end{tabular}
\label{tab:fig1}
\end{table}
\end{document}
我写的地方\notableentry
就是我需要划掉的单元格,并且用红色标注。
提前致谢。
答案1
既然您已经使用 tikz 计算出单元格的角,那么您可能根本不使用 colortbl,而是使用 tikz 填充矩形。(也许可以优化 tikz 以共享坐标的计算,但这是可行的。)
\documentclass{article}
\usepackage{pgf,tikz,colortbl}
\usetikzlibrary{arrows}
\usetikzlibrary{babel}
\usetikzlibrary{calc}
\usepackage{zref-savepos}
%
%
\newcounter{NoTableEntry}
\renewcommand*{\theNoTableEntry}{NTE-\the\value{NoTableEntry}}
%
\newcommand*{\notableentry}{%
\multicolumn{1}{@{}c@{}|}{%
\stepcounter{NoTableEntry}%
\vadjust pre{\zsavepos{\theNoTableEntry t}}% top
\vadjust{\zsavepos{\theNoTableEntry b}}% bottom
\zsavepos{\theNoTableEntry l}% left
\hspace{0pt plus 1filll}%
\zsavepos{\theNoTableEntry r}% right
\tikz[overlay]{%
\fill[red]
let
\n{llx}={\zposx{\theNoTableEntry l}sp-\zposx{\theNoTableEntry r}sp},
\n{urx}={0},
\n{lly}={\zposy{\theNoTableEntry b}sp-\zposy{\theNoTableEntry r}sp},
\n{ury}={\zposy{\theNoTableEntry t}sp-\zposy{\theNoTableEntry r}sp}
in
(\n{llx}, \n{lly}) rectangle (\n{urx}, \n{ury})
;
\draw[black]
let
\n{llx}={\zposx{\theNoTableEntry l}sp-\zposx{\theNoTableEntry r}sp},
\n{urx}={0},
\n{lly}={\zposy{\theNoTableEntry b}sp-\zposy{\theNoTableEntry r}sp},
\n{ury}={\zposy{\theNoTableEntry t}sp-\zposy{\theNoTableEntry r}sp}
in
(\n{llx}, \n{lly}) -- (\n{urx}, \n{ury})
(\n{llx}, \n{ury}) -- (\n{urx}, \n{lly})
;
}%
}%
}
\begin{document}
\begin{table}
\centering
\caption{Activities.}
\begin{tabular}{|c|c|}
\hline
Activities & \rotatebox[origin=c]{-90}{August 2016} \\
%
\hline Introduction & \notableentry \\
\hline
\end{tabular}
\label{tab:fig1}
\end{table}
\end{document}