Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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} 
share|improve this question

2 Answers 2

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]).

share|improve this answer

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}
    \addplot[domain=0:360] {sin(x)};
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
    
I think you can get away with it if you make sure that no grid and axis lines are drawn in the dummy axis. –  percusse Feb 1 '13 at 11:03
    
@percuße I don't think I understood what you meant. Shouldn't the empty axis be enough? Is there any way to force no grid nor axis in this empty axis? –  perr0 Feb 1 '13 at 16:19
    
@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
    
@percuße so, the code you suggest would be different from this one? –  perr0 Feb 1 '13 at 19:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.