带阴影的节点标签

带阴影的节点标签

在某些情况下,某些图片中的所有节点tikz都有阴影。例如,可以通过以下方式实现:

every node/.style = {draw, fill=white, drop shadow},

问题出现了,如果我想给这些节点添加标签。这些标签也有阴影,我不喜欢。我尝试用

no shadows/.style = {general shadow/.style=},

但这不起作用(正如我所料):

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shadows}

\begin{document}
    \begin{tikzpicture}[
every node/.style = {draw, fill=white, drop shadow},
no shadows/.style = {general shadow/.style=}, % should remove drop shadow, but not
every label/.append style = {label distance=1em, font=\scriptsize, no shadows}
                        ]
\node[label=how to remove label shadow?]  {node with shadow};
    \end{tikzpicture}
\end{document}

enter image description here

编辑: 提出问题并姆韦更清晰:

  • no shadows/.style = {general shadow/.style=},取自奎伯比尔贝尔回答问题在这里代码中描述A
  • 他的代码解决方案我没有测试,因为它需要(据我理解代码)

    \makeatletter \tikzset{no shadows/.code=\let\tikz@preactions\pgfutil@empty} \makeatother

    应该在序言中,但由于某些原因,不喜欢

  • 该解决方案应应用于所有标签,即它可以用作样式选项 -every label/.append style = {<other style's definitions>, no shadows} 现在我想知道为什么 [Qrrbrbirlbel] 的解决方案在代码示例中有效A其中no shadows是选项child而不是节点。如果我将其移动到节点,那么此代码也无法正常工作。

到目前为止提供的优雅解决方案Torbjørn T.,使标签阴影不可见,满足了我所有的期望。在撰写本文时,解决方案土拨鼠仍在进行/发展中。

答案1

您可以在样式every shadow内修改样式every label。例如,添加every shadow/.style={opacity=0}every label使阴影不可见。

enter image description here

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shadows}

\begin{document}
    \begin{tikzpicture}[
every node/.style = {draw, fill=white, drop shadow},
every label/.append style = {
     label distance=1em,
     font=\scriptsize,
     every shadow/.style={opacity=0} % <- add this
  }
                        ]
\node [label=foobar]  {node with shadow};
    \end{tikzpicture}
\end{document}

答案2

好吧,我不知道你不喜欢这些\makeatletter东西。在这种情况下,我认为 Torbjørn T. 的解决方案是最好的。这是一个替代方案,它的优点是可以本地关闭阴影(不是每个阴影),但最大的缺点是它会将白框放在可能存在的其他东西之上。我已经检查过这个版本也可以附加到every label

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shadows,positioning}

\begin{document}
    \begin{tikzpicture}[
every node/.style = {draw, fill=white, drop shadow},
no shadows/.style = {drop shadow={fill=white,opacity=1,shadow scale=1.01}}, % should remove drop shadow, but not
%no shadows/.code = {\pgfextra{\tikzset{general shadow/.style=}}}, % should remove drop shadow, but not
every label/.append style = {label distance=1em, font=\scriptsize}
]

%\tikzset{general shadow/.style=}                        ]
\node[label=how to remove label shadow?] (A)  {node with shadow};
\node[right=1cm  of A, label={[no shadows]shadow removed from label?}] (B) {node with shadow};
    \end{tikzpicture}
\end{document}

enter image description here

我想说的是,如果需要的话,在本地关闭阴影可能会有好处,正如所描述的这里

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shadows}
\makeatletter % from https://tex.stackexchange.com/a/129322/121799
\tikzset{no shadows/.code=\let\tikz@preactions\pgfutil@empty}
\makeatother

\begin{document}
    \begin{tikzpicture}[
every node/.style = {draw, fill=white, drop shadow},
every label/.append style = {
     label distance=1em,
     font=\scriptsize,
  }
                        ]
\node [label={[no shadows]foobar}]  {node with shadow};
    \end{tikzpicture}
\end{document}

enter image description here

这里是 Zarko 的一个特别之处,它产生相同的输出:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shadows}
\makeatletter % from https://tex.stackexchange.com/a/129322/121799
\tikzset{no shadows/.code=\let\tikz@preactions\pgfutil@empty}
\tikzset{every label/.append code=\let\tikz@preactions\pgfutil@empty}
\makeatother

\begin{document}
    \begin{tikzpicture}[
every node/.style = {draw, fill=white, drop shadow},
every label/.append style = {
     label distance=1em,
     font=\scriptsize,
  }
                        ]
\node [label={foobar}]  {node with shadow};
    \end{tikzpicture}
\end{document}

希望解决评论中讨论的问题(仔细阅读后)这个答案;-):

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shadows}
\makeatletter % from https://tex.stackexchange.com/a/129322/121799
\tikzset{no shadows/.code=\let\tikz@preactions\pgfutil@empty}
\makeatother

\begin{document}
    \begin{tikzpicture}[
every node/.style = {draw, fill=white, drop shadow},
every label/.append style = {
     label distance=1em,
     font=\scriptsize,
     fill=blue,
     no shadows
  }
                        ]
\node [label=foobar]  {node with shadow};
    \end{tikzpicture}
\end{document}

enter image description here

相关内容