1

I am currently trying to create a freehand style as seen in technical drawings:

image of a technical drawing with a part cut out

(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:

reproduction of the technical drawing in tikz with an issue

However, the line and the background don't match.

I think I can fix this through either

  1. setting a random seed to the same value for both parts
  2. use filldraw from the beginning
  3. 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.

  • 1
    Applying the duplicate to your case would be something like \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
  • 1
    But to fill both sides of the line you could also fill the rectangle first and then draw the second fill on top I guess (but I didn't try that). – Marijn Mar 06 '21 at 11:39

0 Answers0