2

Consider the following LaTeX manuscript featuring a new PDF decoration declaration followed by its use on a simple line. The code is modeled after the examples on p. 999 of the TikZ & PGF manual for version 3.0.1a.

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations}
\begin{document}
    \pgfdeclaredecoration{example}{initial}
    {
        \state{initial}[width=1cm]
        {
            \pgfpathlineto{\pgfpoint{0pt}{1cm}}
        }
    }
    \tikz[decoration=example]
    {
        \draw[decorate] (0,0) -- (4,0);
    }
\end{document}

The resulting picture is

PGF decoration - actual picture

This is not what I expected. I expected there to be four parallel vertical segments spaced 1cm apart.

  • Add \draw[red,thick] (0,0) -- (4,0); to see what happened to the initial 1cm. – percusse Jul 18 '17 at 17:50
  • @percusse: I've added the code, but I still don't understand why the decoration looks like it does. – Evan Aad Jul 18 '17 at 17:54
  • 1
    It puts the pen down draws the vertical and removes 1cm from the path. Because you don't come back to the original path position continues the remaining path, 3cm, from the last position you left off which is (0,1) and position is already (0,1) at each 1cm so you don't see anything – percusse Jul 18 '17 at 18:16
  • @percusse: This is a good explanation. I get it now. – Evan Aad Jul 18 '17 at 18:50
1

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations}
\begin{document}
    \pgfdeclaredecoration{example}{initial}
    {%
        \state{initial}[width=1cm]%
        {%
            \pgfpathmoveto{\pgfpoint{0pt}{0cm}}%
            \pgfpathlineto{\pgfpoint{0pt}{1cm}}%
        }%
\state{final}
{
   \pgfpathmoveto{\pgfpointdecoratedpathlast}
}
}
    \tikz[decoration=example]%
    {%
        \draw[decorate] (0,0) -- (4,0);
    }

\end{document}
  • Why does the addition of \pgfpathmoveto{\pgfpoint{0pt}{0cm}} matter? The examples on p. 999 in the manual don't use a \pgfpathmoveto command. – Evan Aad Jul 18 '17 at 18:38
  • @EvanAad no but they draw path components, you could use lineto here as well but then (as in the examples in the manual) you'd get a connected line you only wanted to draw part of the path so you want to oscillate between moveto and lineto. – David Carlisle Jul 18 '17 at 18:40

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.