3

I want to use a complex decoration, and then apply it to a curved path. It seems as if TikZ does not bend single segments though. Do you have any idea how I could get the desired behavior?

Is there maybe a way to add paths, similar to the stacked plots in pgfplots?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations}

\pgfdeclaredecoration{reserve}{initial}
{
  \state{initial}[width=\pgfdecoratedpathlength]
  {
    \pgfpathlineto{\pgfpoint{0pt}{-4pt}}
    \pgfpathlineto{\pgfpoint{0.15*\pgfdecoratedpathlength}{7pt}}
    \pgfpathlineto{\pgfpoint{0.2*\pgfdecoratedpathlength}{-7pt}}
    \pgfpathlineto{\pgfpoint{0.35*\pgfdecoratedpathlength}{5pt}}
    \pgfpathlineto{\pgfpoint{0.4*\pgfdecoratedpathlength}{-5pt}}
    \pgfpathcurveto{\pgfpoint{0.5*\pgfdecoratedpathlength}{3pt}}{\pgfpoint{0.6*\pgfdecoratedpathlength}{-3pt}}{\pgfpoint{0.6*\pgfdecoratedpathlength}{-3pt}}
    \pgfpathlineto{\pgfpoint{0.65*\pgfdecoratedpathlength}{6pt}}
    \pgfpathlineto{\pgfpoint{0.82*\pgfdecoratedpathlength}{-7pt}}
    \pgfpathlineto{\pgfpoint{0.9*\pgfdecoratedpathlength}{7pt}}
    \pgfpathlineto{\pgfpoint{0.97*\pgfdecoratedpathlength}{-2pt}}
    \pgfpathlineto{\pgfpoint{\pgfdecoratedpathlength}{0pt}}
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpointdecoratedpathlast}
  }
}

\begin{document}
\begin{tikzpicture}
  \draw[black, decorate, decoration={name=reserve}, very thick] (0,5) -- (5, 5) ;
  \draw[black, decorate, decoration={name=reserve}, very thick] (0,0) to[bend left] (5, 0) ;
\end{tikzpicture}
\end{document}

decoration applied to straight and curved line

  • You would get a better result with a meta decoration – percusse Apr 26 '14 at 9:41
4

Decorations work by breaking things into small sections and fitting them to the path independently. I couldn't get it to work using \pgfdecoratedpathlength, though.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations}

\pgfdeclaredecoration{reserve}{initial}
{
  \state{initial}[width=1cm,next state=break1]
  {
    \pgfpathlineto{\pgfpoint{0pt}{-4pt}}
    \pgfpathlineto{\pgfpoint{0.75cm}{7pt}}
    \pgfpathlineto{\pgfpoint{1cm}{-7pt}}
  }
  \state{break1}[width=1cm,next state=break2]
  {
    \pgfpathlineto{\pgfpoint{.75cm}{5pt}}
    \pgfpathlineto{\pgfpoint{1cm}{-5pt}}
  }
  \state{break2}[width=1cm,next state=break3]
  {
    \pgfpathcurveto{\pgfpoint{.5cm}{3pt}}{\pgfpoint{1cm}{-3pt}}{\pgfpoint{1cm}{-3pt}}%
  }
  \state{break3}[width=1cm,next state=break4]
  {
    \pgfpathlineto{\pgfpoint{.25cm}{6pt}}
    \pgfpathlineto{\pgfpoint{1cm}{-7pt}}
  }
  \state{break4}[width=1cm]
  {
    \pgfpathlineto{\pgfpoint{.5cm}{7pt}}
    \pgfpathlineto{\pgfpoint{.9cm}{-2pt}}
    \pgfpathlineto{\pgfpoint{1cm}{0pt}}
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpointdecoratedpathlast}
  }
}

\begin{document}
\begin{tikzpicture}
  \draw[black, decorate, decoration={name=reserve}, very thick] (0,5) -- (5cm,5) ;
  \draw[black, decorate, decoration={name=reserve}, very thick] (0,0) to[bend left] (5, 0) ;
\end{tikzpicture}
\end{document}

decoration

  • Thanks a lot for the help! This works in my case, as I only need to use the decoration for one specific picture and thus am not dependent on the \pgfdecoratedpathlength – Theo Apr 28 '14 at 11:48

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.