Tikz 样式,可通过 \tikzset 来禁用文本

Tikz 样式,可通过 \tikzset 来禁用文本

我正在寻找一个\tikzset可以禁用文本渲染。\draw我可以用 来表示draw=none,如 (2) 中所述,但是有没有等同于 的东西text=none我也可以用它来禁用文本。

这种微弱的尝试text=white不会奏效,因为它在文本位于图片其他部分的情况下失败了,就像在 (3) 中一样。

在此处输入图片描述

代码:

\documentclass{article}
\usepackage{tikz}

\tikzset{Line Draw Style/.style={ultra thick, gray}}
\tikzset{Text Style/.style={}}

\newcommand*{\MyTikzPicture}[1] {%
    \begin{tikzpicture}
        \draw [draw=green, ultra thick] (1,0) -- (2,0); % Should only be visible in (2)
        \draw [ultra thick, Line Draw Style] (0,0) -- (3,0) 
            node [pos=0.5, ultra thick, text=black, Text Style] {$A$}
            node [pos=0, left, text=black] {(#1)};
    \end{tikzpicture}%
}

\begin{document}
    \MyTikzPicture{1}

\begingroup
    \tikzset{Line Draw Style/.style={draw=none}}%
    \tikzset{Text Style/.style={text=blue, font=\bfseries}}%
    \MyTikzPicture{2}
\endgroup

\begingroup
    \tikzset{Line Draw Style/.style={draw=red}}%
    \tikzset{Text Style/.style={text=white}}% <--- What can I do here to disable the text
    \MyTikzPicture{3}
\endgroup
\end{document}

答案1

除此之外text opacity,您还可以使用node contents

\newcommand*{\MyTikzPicture}[1] {%
    \begin{tikzpicture}
        \draw [draw=green, ultra thick] (1,0) -- (2,0); % Should only be visible in (2)
        \draw [ultra thick, Line Draw Style] (0,0) -- (3,0)
            node [pos=0.5, ultra thick, text=black, node contents={$A$}, Text Style] {} %%<-- here
            node [pos=0, left, text=black] {(#1)};
    \end{tikzpicture}%
}

当你不需要文本时,用以下方式覆盖内容为空

\tikzset{Text Style/.style={node contents={}}}% <--- What can I do here to disable the text

代码:

\documentclass{article}
\usepackage{tikz}

\tikzset{Line Draw Style/.style={ultra thick, gray}}
\tikzset{Text Style/.style={}}

\newcommand*{\MyTikzPicture}[1] {%
    \begin{tikzpicture}
        \draw [draw=green, ultra thick] (1,0) -- (2,0); % Should only be visible in (2)
        \draw [ultra thick, Line Draw Style] (0,0) -- (3,0)
            node [pos=0.5, ultra thick, text=black, node contents={$A$}, Text Style] {}
            node [pos=0, left, text=black] {(#1)};
    \end{tikzpicture}%
}

\begin{document}
    \MyTikzPicture{1}

\begingroup
    \tikzset{Line Draw Style/.style={draw=none}}%
    \tikzset{Text Style/.style={text=blue, font=\bfseries}}%
    \MyTikzPicture{2}
\endgroup

\begingroup
    \tikzset{Line Draw Style/.style={draw=red}}%
    \tikzset{Text Style/.style={node contents={}}}% <--- What can I do here to disable the text
    \MyTikzPicture{3}
\endgroup
\end{document}

在此处输入图片描述

相关内容