Tikz 矩形分割不透明度问题

Tikz 矩形分割不透明度问题

我怎样才能在灰色文本框下画红线?白色背景应该是透明的。

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{shapes}

\tikzstyle{style}=[rectangle split, rectangle split parts=2, rectangle split part fill={white, gray}, rectangle split horizontal=false, draw=black, thick]

\begin{document}
\begin{tikzpicture}
  \node[style, minimum size=5cm](A) {
      \begin{tikzpicture}
        \node[style, minimum size=2cm](B) {
          123456789123456789
          \nodepart{two}TEXT};
      \end{tikzpicture}
      \nodepart{two}TEXT
  };
  \draw[-, red, thick](A.north west) -- (A.south east);
\end{tikzpicture}
\end{document}

答案1

是這樣嗎?

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{shapes,calc}

\tikzstyle{style}=[rectangle split, rectangle split parts=2, rectangle split part fill={white, gray}, rectangle split horizontal=false, draw=black, thick]

\begin{document}
\begin{tikzpicture}
  \node[style, minimum size=5cm](A) {
      \begin{tikzpicture}
        \node[style, minimum size=2cm](B) {
          123456789123456789
          \nodepart{two}TEXT};
      \end{tikzpicture}
      \nodepart{two}TEXT
  };
  \draw[-, red, thick]($(A.south west) + (0,-.5ex)$) -- ($(A.south east) + (0,-.5ex)$);
\end{tikzpicture}
\end{document}

在此处输入图片描述

或这个:

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{shapes,calc}

\tikzset{
style/.style={rectangle split, rectangle split parts=2, rectangle split part fill={white, gray}, rectangle split horizontal=false, draw=black, thick}
}

\begin{document}
\begin{tikzpicture}
  \node[style, minimum size=5cm](A) {
      \begin{tikzpicture}
        \node[style, minimum size=2cm](B) {
          123456789123456789
          \nodepart{two}TEXT};
          \draw[-, red, thick]($(B.south west) + (0,-.5ex)$) -- ($(B.south east) + (0,-.5ex)$);
      \end{tikzpicture}
      \nodepart{two}TEXT
  };
  \draw[-, red, thick]($(A.south west) + (0,-.5ex)$) -- ($(A.south east) + (0,-.5ex)$);
\end{tikzpicture}
\end{document}

在此处输入图片描述

tikzpicture在 inside使用tikzpicture可能会很麻烦。此外tikzstyle,请使用tikzset(如后一个代码所示)来代替 ,因为前者已被弃用。

或这个:

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds}

\tikzset{
style/.style={rectangle split, rectangle split parts=2, rectangle split part fill={none, gray}, rectangle split horizontal=false, draw=black, thick}
}

\begin{document}
\begin{tikzpicture}
  \node[style, minimum size=5cm,opacity=1](A) {
      \begin{tikzpicture}
        \node[style, minimum size=2cm](B) {
          123456789123456789
          \nodepart{two}TEXT};
      \end{tikzpicture}
      \nodepart{two}TEXT
  };
  \begin{pgfonlayer}{background}
  \draw[-, red, thick,](A.north west) -- (A.south east);
  \end{pgfonlayer}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容