突出显示节点内的标签

突出显示节点内的标签

我是 tikz 新手,我手动创建了一个图像,在该图中,彩色部分显示了突出显示的标签,我如何通过 tikz 执行此操作我正在使用以下代码作为标签,如何更改此代码。

    \documentclass[a3paper]{article}
\usepackage{
            calc,
            graphicx,
            eso-pic,
            tikz,
            }



\begin{document}
\begin{tikzpicture}
  \begin{scope}[local bounding box=scope1]
    \draw (2.1,8) rectangle (6,4);
    \node [transform shape] (Label) at (1.5,4)[rotate=0,color=black] {label-1};
    \node [transform shape] (Label) at (1.5,5)[rotate=0,color=black] {label-2};
    \node [transform shape] (Label) at (1.5,6)[rotate=0,color=black] {label-3};
    \node [transform shape] (Label) at (1.5,7)[rotate=0,color=black] {label-4};
    \node [transform shape] (Label) at (1.5,8)[rotate=0,color=black] {label-5};
  \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

删除该color=black选项,并通过以下方式将样式应用于每个节点every node/.style=

在此处输入图片描述

代码:

\documentclass[a3paper]{article}
\usepackage{calc,graphicx,eso-pic,tikz,}

\tikzset{My Node Style/.style={draw=pink, fill=pink, fill opacity=0.50, text opacity=1}}

\begin{document}
\begin{tikzpicture}
  \begin{scope}[local bounding box=scope1,
  every node/.style={My Node Style}
  ]
    \draw (2.1,8) rectangle (6,4);
    \node [transform shape] (Label) at (1.5,4) {label-1};
    \node [transform shape] (Label) at (1.5,5) {label-2};
    \node [transform shape] (Label) at (1.5,6) {label-3};
    \node [transform shape] (Label) at (1.5,7) {label-4};
    \node [transform shape] (Label) at (1.5,8) {label-5};
  \end{scope}
\end{tikzpicture}
\end{document}

相关内容