4
  • I want a standalone diagram (standalone document class plus pgfplots package).
  • I want that the diagram doesn't dance around when I have multiple diagrams with different axis limits and so on.
  • Therefore I use scale only axis and trim the bounding box to the axis (see MWE).
  • All works fine but the border option of the standalone package seems not to work.
  • border = {15mm 0mm 0mm 0mm} % left bottom right top should add a border to the left side but it adds a border to all four sides.
  • The yellow background is only to make the example clearer.

% https://tex.stackexchange.com/questions/123880/
\documentclass[
    tikz,
    border = {15mm 0mm 0mm 0mm} % left bottom right top
    ]
    {standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        xlabel = $x$,
        ylabel = {$y$},
        xmin = 0,
        xmax = 30,
        ymin = 0,
        ymax = 100,     
        xtick = {0,10,...,30},  
        ytick = {0,10,...,100}, 
        scale only axis,
        % https://tex.stackexchange.com/questions/153708/
        execute at end picture={
            \pgfresetboundingbox
            \path (current axis.north west) (current axis.south east);
        },  
        % https://tex.stackexchange.com/questions/239294
        axis background/.style={fill=yellow}    
    ]
    %
    \addplot[]{x^2};        
    %       
    \end{axis}
\end{tikzpicture}

\end{document}

border = {0mm 0mm 0mm 0mm}

enter image description here


border = {15mm 0mm 0mm 0mm}

enter image description here

1 Answers1

6

The option is a bit picky regarding spaces. Compare:

\documentclass[
    border={15mm 0mm 0mm 0mm},% works
   % border= {15mm 0mm 0mm 0mm}%wrong borders
    ]
    {standalone}
\begin{document}
\rule{1cm}{1cm}
\end{document}
Ulrike Fischer
  • 327,261
  • Haha - crazy. Thanks. I think this can be considered a bug. Did you just guess? – Dr. Manuel Kuehner Jun 15 '17 at 15:46
  • 1
    It is not so much a bug but an overstretched use of the class options. The LaTeX code isn't really designed for keyval here, and in this case zap@space removes too much spaces in the failing case. There is no need to setup the border already when loading the class, and imho it would be better if there were a \standalonesetup{...} command. – Ulrike Fischer Jun 15 '17 at 16:19
  • Thanks -- good idea, maybe you mean \standaloneconfig since I did not find \standalonesetup in the manual. – Dr. Manuel Kuehner Jun 15 '17 at 16:31
  • 2
    Oh there is one ;-). I only looked for "setup". Yes, it is better to use this. – Ulrike Fischer Jun 15 '17 at 16:32