1

How can make a partial draw in style definition?

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\begin{document}
\tikzset{%
    myrect/.style={%
    minimum width=2cm, minimum height=1cm, fill=olive!80
    }
}
\begin{tikzpicture}
\node[myrect] (R) at (0, 0){};
\draw[red] (R.north west)--(R.north east);
\end{tikzpicture}
\end{document}

enter image description here

blackened
  • 4,181

1 Answers1

2

one of possibilities is use path picture={...}:

\documentclass[tikz, border=1cm]{standalone}
\newcommand\ppbb{path picture bounding box}

\begin{document}
\tikzset{%
    myrect/.style={%
    minimum width=2cm, minimum height=1cm, fill=olive!80,
    path picture={%
    \draw[thick,red]       (\ppbb.north west)  --  (\ppbb.north east);
                },    
    }
}
\begin{tikzpicture}
\node[myrect] (R) at (0, 0){};
\end{tikzpicture}
\end{document}

enter image description here

Zarko
  • 296,517