[Tex/LaTex] Use TikZ decoration in a scope

decorationstikz-pgf

Rather than define a single decorator for all lines at the tikzpicture level, I'd like to use scopes to selectively apply certain decorations to certain parts of my drawing. As a minimal example:

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

\begin{document}

\begin{tikzpicture}
%%% Draw the axis.
\begin{scope}[decoration={ticks}]
\draw [->] (0,0) -- (8,0);
\draw [decorate] (0,0) -- (8,0);
\end{scope}
\end{tikzpicture}

\end{document}

This should produce an axis eight units long with tick marks, and the decoration should not "bleed" into other areas of the figure.

Instead, I get an axis, but no tickmarks!

EDIT: It turns out, calling \usetikzlibrary{decorations} in the preamble doesn't work. Instead, use \usetikzlibrary{decorations.pathreplacing}. Can anyone tell me why loading the whole decorations library doesn't work?

Best Answer

It requires the library decorations.pathreplacing. The axis style for a path doesn't exist by default. Perhaps you can clarify that. The code below works. But perhaps not as expected.

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}
  \begin{tikzpicture}
    \begin{scope}[decoration={ticks}]
      \draw[->] (0,0) -- (8,0);
      \draw[decorate] (0,0) -- (8,0);
    \end{scope}
  \end{tikzpicture}
\end{document}