This is a followup question of Is there a way to draw TikZ lines on the “inside” or “outside” of a path?
Since the other question is quite old I want to ask, if TikZ in the meantime is able to draw a stroke inside, on or outside of a path, like in this picture?
This was generated with the following code using \pgflinewidth to change the actual path. But this solution doesn’t work for arbitrary shapes and not for nodes, furthermore it is broken when scaling the picture.
\documentclass[border=5mm,tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[
every node/.style = {below=5mm, text=black, font=\small},
% scale = 1.5,
]
% path
\draw [red] (0,0) rectangle +(2,2)
+(1,0) node {actual path};
% stroke on path
\draw [line width = 4mm] (3,0) rectangle +(2,2);
\draw [red] (3,0) rectangle +(2,2)
+(1,0) node {stroke on path};
% stroke inside path
\draw [line width = 4mm]
($(6,0)+(\pgflinewidth/2,\pgflinewidth/2)$) rectangle
+($(2,2)-(\pgflinewidth,\pgflinewidth)$);
\draw [red] (6,0) rectangle +(2,2)
+(1,0) node {stroke inside path};
% stroke outsie path
\draw [line width = 4mm]
($(9,0)-(\pgflinewidth/2,\pgflinewidth/2)$) rectangle
+($(2,2)+(\pgflinewidth,\pgflinewidth)$);
\draw [red] (9,0) rectangle +(2,2)
+(1,0) node {stroke outside path};
\end{tikzpicture}
\end{document}
Actually I need it for drawing a row of nodes where some of them are filled and some are drawn, but the total hight should be equal and they should’t overlap. This is how it should not look like:
Instead the stroke of “State B” and “State C” should lie inside of the path. (The postaction is only for demonstration.)
Code:
\begin{tikzpicture}[
every node/.style = {
inner sep=0pt, outer sep=0pt, postaction = {draw, red, thin},
minimum height = 8mm, anchor = south west, font=\small
},
a/.style = {fill = gray},
b/.style = {draw, line width = 2mm},
c/.style = {draw, line width = 2mm, shape = signal },
]
\node at (0,0) [minimum width = 20mm, a] {State A};
\node at (2,0) [minimum width = 20mm, b] {State B};
\node at (4,0) [minimum width = 30mm, a] {State A};
\node at (7,0) [minimum width = 30mm, c] {State C};
\draw [->] (0,-0.5) -- +(10.5,0);
\foreach \x in {0,0.5,...,10}
\draw (\x,-0.6) -- (\x,-0.4);
\end{tikzpicture}




\node[clip,postaction={draw,ultra thick}] {...};– percusse Feb 05 '16 at 13:16