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

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.