# Fix append pgfplots style to all pictures breaking plain TikZ compilation

I have the following code in my preamble to align the pgfplots in my document.

\pgfplotsset{
every axis/.append style={
scale only axis
},
/tikz/every picture/.append style={
trim axis left,
trim axis right,
}
}


But the last part (/tikz/every picture/.append style...) breaks compilation for TikZ picture that don't use pgfplots, since there is no axis in it.

Currently, I have to comment that part of the code, then compile all plain TikZ drawings, then uncomment and compile all pgfplots figures, then mix them together. I have \tikzexternalize in my preable to, so I keep figures in separate files after compiling each of them.

This is a big hassle. How can I get pgfplots alignment and avoid this issue?

Here's a MWE that reproduces the problem:

\documentclass{article}

\usepackage{pgfplots,tikz}

\pgfplotsset{
every axis/.append style={
scale only axis
},
/tikz/every picture/.append style={
trim axis left,
trim axis right,
}
}

\begin{document}
\begin{tikzpicture}

\draw[very thick,->] (-1,-1) -- (1,1);

\end{tikzpicture}
\end{document}

-

Your code explicitly requests to apply the bounding box modifications for every picture.

I suppose the correct solution is to write a named style (i.e. something like trimmed picture instead of every picture) and use that named style explicitly in every picture for which it is to be applied (i.e. \begin{tikzpicture}[trimmed pictured]).

-

I'm not sure whether this leads to spacing issues or others, but just adding an empty axis to every picture gets rid of the error:

\documentclass{article}

\usepackage{pgfplots,tikz}

\pgfplotsset{
every axis/.append style={
scale only axis
},
/tikz/execute at begin picture={
\begin{axis}, \end{axis},
}
/tikz/every picture/.append style={
trim axis left,
trim axis right,
}
}

\begin{document}
\begin{tikzpicture}

\draw[very thick,->] (-1,-1) -- (1,1);

\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}

@perr0 Well, if you also include every axis stiff those dummy axes would effected too. So it's best to include the nondrawing axis lines and grid lines as precautions. –  percusse Feb 1 '13 at 16:25