我知道三种方法可以“忽略”或至少“隐藏” Ti 中的某些内容钾Z 使用[...]
或\tikzset{bla/.style={...}}
:
[draw=none]
(对 的作用类似于 魅力,但对内容\draw
不起作用;node
[white]
(适用于所有人,但涵盖其他内容,文本仍然存在并可复制粘贴);[text opacity=0]
(适用于所有人,但意味着 PDF 具有透明度,并且文本仍然存在且可复制粘贴)。
那么:真的没有解决方案可以让图纸(尤其是节点)完全消失吗?这需要使用\tikzset{bla./style={...}}
。
可供玩耍的 MWE:
\documentclass[tikz,margin=5pt]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (10,10);
\draw (0,0) -- (2,2);
\draw[draw=none] (0,1) -- (2,3);
\node at (3,3) {BLA};
\node[white] at (3,4) {BLA};
\node[text opacity=0] at (3,5) {BLA};
\node[blue,draw,rectangle] at (7,3) {FOO};
\node[blue,draw,rectangle,draw=none,text opacity=0] at (7,4) {FOO};
\end{tikzpicture}
\end{document}
答案1
ignore
另一种方式是使用execute at begin node
和定义样式execute at end node
来框住内容而不是使用框;这样做的好处是你可以忽略所有类型的材料(参见带有图像的示例):
\documentclass[tikz,margin=5pt]{standalone}
\usepackage{graphicx}
\newsavebox\mybox
\tikzset{
ignore/.style={
execute at begin node={\begin{lrbox}{\mybox}},
execute at end node={\end{lrbox}}
}
}
\begin{document}
\begin{tikzpicture}[xshift=20cm]
\draw (0,0) rectangle (10,10);
\draw[draw=none] (0,0) -- (2,2);
\draw[draw=none] (0,1) -- (2,3);
\node[ignore] at (3,3) {BLA};
\node[ignore] at (3,4) {BLA};
\node[ignore] at (3,5) {BLA};
\node[blue,draw=none,rectangle,ignore] at (7,3) {FOO};
\node[blue,rectangle,draw=none,ignore] at (7,4) {FOO};
\node[blue,rectangle,draw=none,ignore] at (7,4) {FOO};
\node[ignore] at (5,5) {\includegraphics[width=3cm]{example-image-a}};
\end{tikzpicture}
\end{document}
结果:
你可以ignore
改为
ignore/.style={
execute at begin node={\begin{lrbox}{\mybox}},
execute at end node={\end{lrbox}},
draw=none,
fill=none
}
然后您也可以使用以下样式忽略\draw
, 或(或类似):\filldraw
\documentclass[tikz,margin=5pt]{standalone}
\usepackage{graphicx}
\newsavebox\mybox
\tikzset{
ignore/.style={
execute at begin node={\begin{lrbox}{\mybox}},
execute at end node={\end{lrbox}},
draw=none,
fill=none
}
}
\begin{document}
\begin{tikzpicture}[xshift=20cm]
\draw (0,0) rectangle (10,10);
\draw[draw=red,ignore] (0,0) -- (2,2);
\filldraw[draw=red,fill=blue,ignore] (4,4) rectangle ++(2,2);
\draw[draw=blue,ignore] (0,1) -- (2,3);
\node[ignore] at (3,3) {BLA};
\node[ignore] at (3,4) {BLA};
\node[ignore] at (3,5) {BLA};
\node[blue,fill=blue,rectangle,ignore] at (7,3) {FOO};
\node[blue,rectangle,ignore] at (7,4) {FOO};
\node[blue,rectangle,ignore] at (7,4) {FOO};
\node[ignore] at (5,5) {\includegraphics[width=3cm]{example-image-a}};
\end{tikzpicture}
\end{document}
答案2
\documentclass[tikz,margin=5pt]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (10,10);
\draw[draw=none] (0,0) -- (2,2);
\draw[draw=none] (0,1) -- (2,3);
\node[font=\nullfont] at (3,3) {BLA};
\node[font=\nullfont] at (3,4) {BLA};
\node[font=\nullfont] at (3,5) {BLA};
\node[blue,draw=none,rectangle,font=\nullfont] at (7,3) {FOO};
\node[blue,rectangle,draw=none,font=\nullfont] at (7,4) {FOO};
\end{tikzpicture}
\end{document}