矩阵环境中的标签意外应用了阴影

矩阵环境中的标签意外应用了阴影

我正在尝试为节点添加阴影。对于普通节点,阴影不会影响标签。但是,对于矩阵内的节点,标签也会被阴影覆盖。

低于

\documentclass[border=5mm, convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning, matrix, shadows}

\begin{document}
    \begin{tikzpicture}[auto]
        \tikzset{myrect/.style={draw, rectangle, font=\ttfamily, fill=white, drop shadow}}
        \tikzset{mylabel/.style={color=blue, font=\tiny \ttfamily}}
        \node[myrect, label={[mylabel]above:normal label}] (ele) {Single Element};

        \matrix (layer) [matrix of nodes, nodes={myrect, anchor=center}, column sep = 1cm, below = of ele] {
            |[label={[mylabel]:matrix label 1}]|matrix element 1 &
            |[label={[mylabel]:matrix label 2}]|matrix element 2 &
            |[label={[mylabel]:matrix label 3}]|matrix element 3 \\
        };
    \end{tikzpicture}
\end{document}

输出如下:在此处输入图片描述

这是怎么发生的?有什么办法可以避免吗?

答案1

一种方法是调整你的style-set定义(正如所做的那样@marmot):

 \documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shadows, shapes, positioning, matrix}
\makeatletter % from https://tex.stackexchange.com/a/129322/121799
\tikzset{no shadows/.code=\let\tikz@preactions\pgfutil@empty}
\makeatother
%https://tex.stackexchange.com/questions/422782/labels-of-nodes-with-drop-shadow
\begin{document}
    \begin{tikzpicture}[
    every node/.style = {font= \ttfamily, draw, fill=white, drop shadow},
    every label/.append style = {
        font=\tiny \ttfamily,
        color = blue,
    }
    ]
    \node [label={[no shadows]foobar}]  (ele) {node with shadow};
    \matrix (layer) [no shadows, matrix of nodes, draw = none, column sep = 1cm, below = of ele] {
        |[label={[no shadows]:matrix label 1}]|matrix element 1 &
        |[label={[no shadows]:matrix label 2}]|matrix element 2 &
        |[label={[no shadows]:matrix label 3}]|matrix element 3 \\
    };
    \end{tikzpicture}
\end{document}

这应该给你:

在此处输入图片描述

相关内容