我正在尝试删除表格中的单元格,没有指定单元格宽度。为此,我查看了代码,colortbl
因为这似乎可以很好地填充单元格。
现在我尝试了所有这些\@tempdim
,但没有任何成功。老实说,我不知道我在做什么。
如果可能的话,我想摆脱tikz
。
到目前为止我尝试过
\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{tikz,colortbl}
\makeatletter
\newcommand*\notableentry{%
\@tempdima\wd\z@
\advance\@tempdima\@tempdimb
\advance\@tempdima\@tempdimc
\tikz[remember picture]{\coordinate (X) at (-.5\tabcolsep-\@tempdima-\@tempdimb-\@tempdimc,-1.1\tabcolsep);}
\hskip\@tempdima\@plus 1fill
\kern-\tabcolsep
\hskip-\wd\z@ \@plus -1fill
\tikz[remember picture]{\coordinate (Y) at (.5\tabcolsep+\@tempdima+\@tempdimb,\@tempdima-.25\tabcolsep);}
}
\makeatother
\begin{document}
\LARGE
\begin{tabular}{|c|c|}
\hline
alghreaiog & bghsah \\
\hline
cagja & \notableentry \\
\hline
\cellcolor{blue} & edkhaklgjaj \\
\hline
\end{tabular}
\tikz[remember picture,overlay]{%
\draw[red] (X) -- (Y);
\draw[red] (X |- Y) -- (Y |- X);
}
\begin{tabular}{|p{4cm}|p{3cm}|}
\hline
alghreaiog & bghsah \\
\hline
cagja\par bla & \notableentry \\
\hline
\cellcolor{blue} & edkhaklgjaj \par xyz \\
\hline
\end{tabular}
\tikz[remember picture,overlay]{%
\draw[red] (X) -- (Y);
\draw[red] (X |- Y) -- (Y |- X);
}
\end{document}
输出
它似乎适用于c
列,但对于所有其他目的却不起作用,尽管它\cellcolor
总是有效。
答案1
下面的示例使用包zref-savepos
来获取单元格的位置。\vadjust pre
(pdfTeX 发明的较新功能,在 LuaTeX 和 XeTeX 中也可用)将位置标记放在当前单元格的正上方,并将\vadjust
标记放在下方。
\notableentry
用于\multicolumn{1}{@{}c@{}|}
获取没有间距的完整单元格宽度\tabcolsep
。\hspace{0pt plus 1filll}
用于覆盖c
说明符以获取单元格左侧和右侧的位置标记。
位置标记(\zsavepos
)的标签名称在计数器的帮助下自动生成NoTableEntry
。
最后计算细胞边界框的坐标并通过绘制十字tikz
。
\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{tikz,colortbl}
\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[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}) -- (\n{urx}, \n{ury})
(\n{llx}, \n{ury}) -- (\n{urx}, \n{lly})
;
}%
}%
}
\begin{document}
\LARGE
\begin{tabular}{|c|c|}
\hline
alghreaiog & bghsah \\
\hline
cagja & \notableentry \\
\hline
\cellcolor{blue} & edkhaklgjaj \\
\hline
\end{tabular}
\begin{tabular}{|p{4cm}|p{3cm}|}
\hline
alghreaiog & bghsah \\
\hline
cagja\par bla & \notableentry \\
\hline
\cellcolor{blue} & edkhaklgjaj \par xyz \\
\hline
\end{tabular}
\end{document}
包装限制pgf
下面的修改将绘图限制在低级包中,pgf
而不是使用前端包tikz
。
\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{colortbl}
\usepackage{pgf}
\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
%
\begin{pgfpicture}%
\pgfsetlinewidth{.4pt}%
\pgfsetstrokecolor{red}%
\edef\llx{0sp}%
\edef\urx{%
\the\numexpr
\zposx{\theNoTableEntry r}%
-\zposx{\theNoTableEntry l}%
\relax sp%
}%
\edef\lly{%
\the\numexpr
\zposy{\theNoTableEntry b}%
-\zposy{\theNoTableEntry l}%
\relax sp%
}%
\edef\ury{%
\the\numexpr
\zposy{\theNoTableEntry t}%
-\zposy{\theNoTableEntry l}%
\relax sp%
}%
\pgfpathmoveto{\pgfpoint{\llx}{\lly}}%
\pgfpathlineto{\pgfpoint{\urx}{\ury}}%
\pgfpathmoveto{\pgfpoint{\llx}{\ury}}%
\pgfpathlineto{\pgfpoint{\urx}{\lly}}%
\pgfusepath{stroke}%
\pgfresetboundingbox
\end{pgfpicture}%
%
\hspace{0pt plus 1filll}%
\zsavepos{\theNoTableEntry r}% right
}%
}
\begin{document}
\LARGE
\begin{tabular}{|c|c|}
\hline
alghreaiog & bghsah \\
\hline
cagja & \notableentry \\
\hline
\cellcolor{blue} & edkhaklgjaj \\
\hline
\end{tabular}
\begin{tabular}{|p{4cm}|p{3cm}|}
\hline
alghreaiog & bghsah \\
\hline
cagja\par bla & \notableentry \\
\hline
\cellcolor{blue} & edkhaklgjaj \par xyz \\
\hline
\end{tabular}
\end{document}
没有pgf
下一个解决方案使用\rotatebox
斜边/对角线的长度旋转规则并\reflectbox
获取十字的另一条对角线。斜边长度和旋转角度的计算是通过包完成的l3fp
。
\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{colortbl}
\usepackage{zref-savepos}
\usepackage{graphicx}
\usepackage{xparse, l3fp}
\ExplSyntaxOn
\NewDocumentCommand { \NTECalcHypotenuse } { m m } {
\fp_to_int:n { sqrt ( #1 * #1 + #2 * #2 ) - 0.5 }
}
\NewDocumentCommand { \NTECalcAngle } { m m } {
\fp_to_decimal:n { atand ( #1 / #2 ) }
}
\ExplSyntaxOff
\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
%
\sbox0{%
\color{red}%
\edef\llx{0}%
\edef\urx{%
\the\numexpr
\zposx{\theNoTableEntry r}%
-\zposx{\theNoTableEntry l}%
\relax
}%
\edef\lly{%
\the\numexpr
\zposy{\theNoTableEntry b}%
-\zposy{\theNoTableEntry l}%
\relax
}%
\edef\ury{%
\the\numexpr
\zposy{\theNoTableEntry t}%
-\zposy{\theNoTableEntry l}%
\relax
}%
\edef\w{\the\numexpr\urx-\llx\relax}%
\edef\h{\the\numexpr\ury-\lly\relax}%
\ifnum\w=0 %
\else
\setbox0=\hbox{%
\edef\angle{\romannumeral-`x\NTECalcAngle{\h}{\w}}%
\raisebox{\the\numexpr\zposy{\theNoTableEntry b}%
-\zposy{\theNoTableEntry l}\relax sp%
}{%
\rotatebox{\angle}{%
\vrule width\NTECalcHypotenuse{\h}{\w}sp height.2pt depth.2pt%
}%
}%
}%
\rlap{\unhcopy0}%
\reflectbox{\unhcopy0}%
\fi
}%
\wd0=0pt %
\ht0=0pt %
\dp0=0pt %
\copy0 %
%
\hspace{0pt plus 1filll}%
\zsavepos{\theNoTableEntry r}% right
}%
}
\begin{document}
\LARGE
\begin{tabular}{|c|c|}
\hline
alghreaiog & bghsah \\
\hline
cagja & \notableentry \\
\hline
\cellcolor{blue} & edkhaklgjaj \\
\hline
\end{tabular}
\begin{tabular}{|p{4cm}|p{3cm}|}
\hline
alghreaiog & bghsah \\
\hline
cagja\par bla & \notableentry \\
\hline
\cellcolor{blue} & edkhaklgjaj \par xyz \\
\hline
\end{tabular}
\end{document}
和pict2e
软件包允许在括号中pict2e
输入 [-16383, 16383] 范围内的任意实数作为斜率参数。因此,该示例使用并重新计算以为单位给出的特征的数字。\line
1pt
\unitlength
\pdfsavepos
sp
pt
\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{colortbl}
\usepackage{zref-savepos}
\usepackage{pict2e}
%\usepackage{picture}
\newcounter{NoTableEntry}
\renewcommand*{\theNoTableEntry}{NTE-\the\value{NoTableEntry}}
\makeatletter
\newcommand*{\notableentry}{%
\multicolumn{1}{@{}c@{}|}{%
\stepcounter{NoTableEntry}%
\vadjust pre{\zsavepos{\theNoTableEntry t}}% top
\vadjust{\zsavepos{\theNoTableEntry b}}% bottom
\zsavepos{\theNoTableEntry l}% left
%
\raisebox{%
\dimexpr\zposy{\theNoTableEntry b}sp
-\zposy{\theNoTableEntry l}sp\relax
}[0pt][0pt]{%
\color{red}%
\setlength{\unitlength}{1pt}%
\edef\w{%
\strip@pt\dimexpr\zposx{\theNoTableEntry r}sp%
-\zposx{\theNoTableEntry l}sp\relax
}%
\edef\h{%
\strip@pt\dimexpr\zposy{\theNoTableEntry t}sp%
-\zposy{\theNoTableEntry b}sp\relax
}%
\ifdim\w pt=0pt % prevent error in first run for \line(0,0)
\else
\begin{picture}(0,0)%
% the arguments of `\line` needs to be expanded,
% because `pict2e' needs to see the decimal dot
\edef\x{%
\noexpand\put(0,0){\noexpand\line(\w,\h){\w}}%
\noexpand\put(0,\h){\noexpand\line(\w,-\h){\w}}%
}\x
\end{picture}%
\fi
}%
\hspace{0pt plus 1filll}%
\zsavepos{\theNoTableEntry r}% right
}%
}
\begin{document}
\LARGE
\begin{tabular}{|c|c|}
\hline
alghreaiog & bghsah \\
\hline
cagja & \notableentry \\
\hline
\cellcolor{blue} & edkhaklgjaj \\
\hline
\end{tabular}
\begin{tabular}{|p{4cm}|p{3cm}|}
\hline
alghreaiog & bghsah \\
\hline
cagja\par bla & \notableentry \\
\hline
\cellcolor{blue} & edkhaklgjaj \par xyz \\
\hline
\end{tabular}
\end{document}
带\notableentry
内部的变体\multicolumn
在此变体中,在with\notableentry
内用作列说明符。这允许在垂直线和十字覆盖的列数方面具有更大的灵活性。\multicolumn
c
\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{colortbl}
\usepackage{zref-savepos}
\usepackage{pict2e}
%\usepackage{picture}
\newcounter{NoTableEntry}
\renewcommand*{\theNoTableEntry}{NTE-\the\value{NoTableEntry}}
\makeatletter
\newcommand*{\notableentry}{%
\kern-\tabcolsep
\stepcounter{NoTableEntry}%
\vadjust pre{\zsavepos{\theNoTableEntry t}}% top
\vadjust{\zsavepos{\theNoTableEntry b}}% bottom
\zsavepos{\theNoTableEntry l}% left
%
\raisebox{%
\dimexpr\zposy{\theNoTableEntry b}sp
-\zposy{\theNoTableEntry l}sp\relax
}[0pt][0pt]{%
\color{red}%
\setlength{\unitlength}{1pt}%
\edef\w{%
\strip@pt\dimexpr\zposx{\theNoTableEntry r}sp%
-\zposx{\theNoTableEntry l}sp\relax
}%
\edef\h{%
\strip@pt\dimexpr\zposy{\theNoTableEntry t}sp%
-\zposy{\theNoTableEntry b}sp\relax
}%
\ifdim\w pt=0pt % prevent error in first run for \line(0,0)
\else
\begin{picture}(0,0)%
% the arguments of `\line` needs to be expanded,
% because `pict2e' needs to see the decimal dot
\edef\x{%
\noexpand\put(0,0){\noexpand\line(\w,\h){\w}}%
\noexpand\put(0,\h){\noexpand\line(\w,-\h){\w}}%
}\x
\end{picture}%
\fi
}%
\hspace{0pt plus 1filll}%
\zsavepos{\theNoTableEntry r}% right
\kern-\tabcolsep
}
\begin{document}
\LARGE
\begin{tabular}{|c|c|}
\hline
alghreaiog & bghsah \\
\hline
\multicolumn{2}{|c|}{\notableentry} \\
\hline
\cellcolor{blue} & edkhaklgjaj \\
\hline
\end{tabular}
\begin{tabular}{|p{4cm}|p{3cm}|}
\hline
alghreaiog & bghsah \\
\hline
cagja\par bla & \multicolumn{1}{c|}{\notableentry} \\
\hline
\cellcolor{blue} & edkhaklgjaj \par xyz \\
\hline
\multicolumn{1}{|c|}{\notableentry} & asdf \\
\hline
\end{tabular}
\end{document}
答案2
colortbl
使用\leaders
with\vrule
添加面板,通常\vrule
扩展到包含框的整个高度/深度,这就是它填充单元格的原因,但是如果指定固定的高度和深度,则会得到一条水平线。请注意,您无法在 TeX 宏层看到框的范围,这将在 TeX 内部的对齐代码中稍后解决。因此,即使\vrule
从上到下绘制一条线,您也不知道“顶部”在哪里,因此您无法在不使用类似\pdfsavepos
tikz 记忆东西正在做的事情的情况下绘制十字线。然后当然,即使您知道坐标,您也需要一些后端代码来绘制给定斜率的线。(您不需要整个 tikz,但您需要一些东西)
碰巧,我在单色屏幕上开发了color
,colortbl
由于黑底黑字有点难以阅读,因此有一个内置选项可以将 colortbl 限制为一条细水平线。(不总是使用此选项很容易,只需有一个本地使用此调试版本的命令,但是:
\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage[debugshow]{colortbl}
\makeatletter
\def\notableentry{\cellcolor{blue}}
\makeatother
\begin{document}
\LARGE
\begin{tabular}{|c|c|}
\hline
alghreaiog & bghsah \\
\hline
cagja & \notableentry \\
\hline
\cellcolor{blue} & edkhaklgjaj \\
\hline
\end{tabular}
\end{document}
答案3
您可以在{NiceTabular}
中执行此操作nicematrix
。
nicematrix
在数组的单元下创建 PGF/Tikz 节点并将它们用于各种功能。
最新版本(5.1 20/07/31)提供了\g_nicematrix_code_after_tl
构建数组后的内部指令。
在下面的代码中,我编写了一个用户命令notableentry
,该命令可以在数组的单元格中使用,并\g_nicematrix_code_after_tl
在构建数组后写入指令以使用 Tikz 指令跨越单元格。
\documentclass{article}
\usepackage{nicematrix,tikz}
\ExplSyntaxOn
\cs_new_protected:Nn \__pantigny_notableentry:nnn
{
\begin { tikzpicture }
\draw [ #3 ]
( #1 -| \int_eval:n { #2 + 1 } )
-- ( \int_eval:n { #1 + 1 } -| #2 )
( #1 -| \int_eval:n #2 )
-- ( \int_eval:n { #1 + 1 } -| \int_eval:n { #2 + 1 } ) ;
\end { tikzpicture }
}
\NewDocumentCommand \notableentry { ! O { } }
{
\tl_gput_right:Nx \g_nicematrix_code_after_tl
{
\__pantigny_notableentry:nnn
{ \int_use:c { c@iRow } }
{ \int_use:c { c@jCol } }
{ \exp_not:n { #1 } }
}
}
\ExplSyntaxOff
\begin{document}
\LARGE
\begin{NiceTabular}{cc}[hvlines,colortbl-like]
alghreaiog & bghsah \\
cagja & \notableentry[red] \\
\cellcolor{blue} & edkhaklgjaj \\
\end{NiceTabular}
\begin{NiceTabular}{p{4cm}p{3cm}}[hvlines,colortbl-like]
alghreaiog & bghsah \tabularnewline
cagja\\ bla & \notableentry[red] \tabularnewline
\cellcolor{blue} & edkhaklgjaj \\ xyz
\end{NiceTabular}
\end{document}
此外,使用 提供的工具为nicematrix
单元格着色在 PDF 查看器中比 获得更好的效果colortbl
。