[Tex/LaTex] tikz: setting up a spring

decorationstikz-pgf

I am trying to set up a spring command but keep receiving the message:

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

The code I have is:

\documentclass[tikz]{standalone}
\usetikzlibrary{patterns}
\usetikzlibrary{decorations}

\begin{document}
\begin{tikzpicture}[decoration = coil,
  spring/.style = {
    decoration = {
      pre length = #1,
      post length = #1}
  }]
  \fill[pattern = north east lines] (-2cm, 0) coordinate (A) rectangle
  (2cm, 0.25cm);
  \draw (A) -- (2cm, 0);
  \draw[decorate, spring = 0.15cm] (-1cm, 0) -- (-1cm, -1cm);
\end{tikzpicture}
\end{document}

Everything is spelled correctly so I am not sure what the issue is.

Best Answer

You need \usetikzlibrary{decorations.pathmorphing}

\documentclass[tikz]{standalone}
\usetikzlibrary{patterns}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
\begin{tikzpicture}[decoration = coil,
  spring/.style = {
    decoration = {
      pre length = #1,
      post length = #1}
  }]
  \fill[pattern = north east lines] (-2cm, 0) coordinate (A) rectangle
  (2cm, 0.25cm);
  \draw (A) -- (2cm, 0);
  \draw[decorate, spring = 0.15cm] (-1cm, 0) -- (-1cm, -1cm);
\end{tikzpicture}
\end{document}