I am currently trying to create a freehand style as seen in technical drawings:
(see the thin line to the right of the shaded part)
This is what I have so far:
\documentclass{article}
% https://tex.stackexchange.com/questions/586063/reusing-decorated-path
\usepackage{tikz}
\usetikzlibrary{decorations, decorations.pathmorphing}
\tikzstyle{freehand}=[decoration = {random steps, amplitude = 10}]
\begin{document}
\begin{tikzpicture}
\draw[thick] (0, 0) rectangle (6, 3);
\draw[thin, freehand, decorate] (3, 0) -- (3, 3);
\fill[red, opacity = .5] (0, 0) -- (3, 0) decorate [freehand] { -- (3, 3)} -- (0, 3);
\end{tikzpicture}
\end{document}
This somewhat does what I want:
However, the line and the background don't match.
I think I can fix this through either
- setting a random seed to the same value for both parts
- use
filldrawfrom the beginning - name the random path & reuse it for the fill command
I couldn't find any way to do 1.
2 I don't like because there could be situations where I want to fill both sides of the lines.
So my question is, how do I save a morphed path to reuse it later?
Thanks in advance.


\pgfmathsetseed{10} \draw[thin, freehand, decorate] (3, 0) -- (3, 3); \pgfmathsetseed{10} \fill[red, opacity = .5] (0, 0) -- (3, 0) decorate [freehand] { -- (3, 3)} -- (0, 3);. – Marijn Mar 06 '21 at 11:37