# Rotate custom shape

Below code create a custom shape 'N'. It works fine with 0 rotation,but if rotate 90 degree, it doesn't work:

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
cap/.style={
rotate=#1,very thick,rectangle,minimum width=2mm,minimum height=4mm,
inner sep=0,outer sep=0,
path picture={
\draw(path picture bounding box.south west) --
(path picture bounding box.north west)
(path picture bounding box.south east) --
(path picture bounding box.north east)
(path picture bounding box.north east) -- (path picture bounding box.south west);
}
},
}
\begin{document}
\begin{tikzpicture}
\node[cap=0] (C1) {};
\node[cap=45,below=0.2 of C1] (C2) {};
\end{tikzpicture}
\end{document}


In this example, C1 is good. C2 is the rotated version:

Two issues:

1. The line width not the same, the middle line looks like more wider.
2. The rotation function doesn't work.

Yes, path pictures are not without subtleties. For this purpose I would, rather than playing with \pgftransformreset and the like, argue that pics may be more straightforward to deal with. Using local bounding boxes one can make them almost behave like nodes.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{positioning}
\tikzset{
pics/.cd,
N/.style={code={\draw[very thick] (-0.1,0.2) -- (-0.1,-0.2)
-- (0.1,0.2) -- (0.1,-0.2);
}}
}
\begin{document}
\begin{tikzpicture}
\pic[local bounding box=C1] {N};
\pic[local bounding box=C2,rotate=45,below=0.4 of C1] {N};
\end{tikzpicture}
\end{document}


your expectation how path picture bounding box is wrong. in your case instead it you can use append after command and add your drawings as follows:

\documentclass[tikz, margin=10pt]{standalone}
\usetikzlibrary{positioning}

\tikzset{
cap/.style={
rotate=#1,very thick,rectangle, minimum width=2mm,minimum height=4mm,
inner sep=0,outer sep=0,
append after command={
\pgfextra{\let\LN\tikzlastnode
\draw   (\LN.south west) -- (\LN.north west) --
(\LN.south east) -- (\LN.north east);
}
},
}% end of cap style
}
\begin{document}
\begin{tikzpicture}
\node[cap=0] (C1) {};
\node[cap=45,below=0.2 of C1] (C2) {};
\end{tikzpicture}
\end{document}


• Great, thanks, but sounds like the rotate is not around center. if rotate C2 with 90 degree, you will find it's not center aligned with C1. – lucky1928 Nov 25 '18 at 20:32
• @lucky1928 The pgfmanual says on p. 162 : "Note that this operation should only be used by real experts and should only be used deep inside clever macros, not on normal paths." I have made too many experiences that suggest that this is to be taken seriously. (You can use \pgfextra for \typeouts and the like without problems, though, according to what I find, but if you use it for paths the outcome is sometimes unpredictable, meaning it can depend on what you've done earlier.) – marmot Nov 25 '18 at 20:37
• @lucky1928, indeed. you should stick with nice marmot answer. – Zarko Nov 25 '18 at 21:00