[Tex/LaTex] TiKZ decoration doesn’t work

decorationstikz-pgf

I am trying to get TikZ decorations to work, but so far without success. In this minimal example, I am trying to compile an example found in pgfmanual.pdf in section 20.2:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations}

\begin{document}
    \begin{tikzpicture}
        \draw decorate [decoration=zigzag] {(0,0) -- (2,2)};
    \end{tikzpicture}
\end{document}

I always get this error

"! Package pgfkeys Error: I do not know the key '/pgf/decoration/crosses'
and I am going to ignore it. Perhaps you misspelled it."

What is the problem?

Best Answer

You need to also load the (sub-)library for the particular decoration (decorations.pathmorphing for zigzag). See also section 51 Decoration Library for more information (using PGF 3.1.5b, the section number can be different for other versions).

One issue with the otherwise great pgfmanual is, that it is hard to know which libraries are required for the examples.

\documentclass{article}

\usepackage{tikz}
%\usetikzlibrary{decorations}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
    \begin{tikzpicture}
        \draw decorate [decoration={zigzag}] {(0,0) -- (2,2)};
    \end{tikzpicture}
\end{document}