反白顯示節點中的標籤

反白顯示節點中的標籤

我是 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}

相關內容