1

As asked here I set up a template for plots that can be used with standalone and included into the main document. 1 remaining problems is that the cropping does not crop enough of the whitespace beyond the x-label. which results in big spaces between x-label and caption, mentioned her. Setting \setlength{\abovecaptionskip}{0pt} in the main document helps reducing the space, but will result in other captions beeing not in the same distance as that of the plots.

The 2. problem is when setting Tex or Build for standalone option the documents still results in different layout, the plots included with build are getting scaled. First Picture shows with \standaloneconfig{mode=tex} the second with \standaloneconfig{mode=build} enter image description here enter image description here

    \begin{filecontents*}{standalone_plot_1.tex}
\documentclass[ class=scrbook, 
convert=false,
border=0pt,% no borders
]{standalone}
% if axis option " only scale axis" is used border has to be set manually to avoid cropping of the Y-Axis Label. Including the standalone then has to be set to \standaloneconfig{mode=tex}
% Using border={0pt 0pt 0pt 0pt} seems not to work with scrbook

% This KOMA options are needed to calculate the Textwitdh and Height
\KOMAoptions{fontsize=12pt} % Fontsize

% the textwidth of the main docement is 16cm=455.24945pt
\newcommand{\originalTextWidth}{455.24945pt}
\newcommand{\originalTextHeight}{591.53027pt}

\usepackage{pgfplots} 

% Option that should not be change by the user, this are set here so it is obvious and makes the code more readable
\pgfplotsset{
    every axis/.append style={
        width=0.75*\originalTextWidth, 
        height=0.1*\originalTextHeight,
        scale only axis, % the width and height specifies only axis not the labels etc. to avoid missplacing of the different plots when Labels are used or not.
    },
}
\tikzset{every picture/.style={trim axis left, trim axis right}}% used to avoid missplacing of different plots when the numbers on the x-axis stands out left or right.

\begin{document}%   
    \makebox[\dimexpr\originalTextWidth\relax]{% Box to avoid problem of standalone cropping too much of the plot.  
        \begin{tikzpicture}
        \begin{axis}[
        xmin=0,xmax=12,%
        xlabel= \fbox{fractions q y Pp f g},
        ylabel=Small Axis,
        ]%
        \addplot[blue, mark=x] coordinates {(0,0)
            (1,2)(2,3)
            (3,4)(4,6)
            (5,11)(6,200)
            (7,15)(8,12)
            (9,8)(10,7)
            (11,3)(12,0)};
        \end{axis}
        \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);%
        %\clip[use as bounding box] (0,0.5)++(current bounding box.south west) rectangle (current bounding box.north east);%
        %\clip[use as bounding box] (0,0)++(.01\textwidth,.01\textwidth) rectangle ++(.45\textwidth,.45\textwidth);
        \end{tikzpicture}% Never Remove this comment to avoid missplacing plot shifts to left side a little bit
    }%End \makebox
\end{document}
\end{filecontents*}

\begin{filecontents*}{standalone_plot_2.tex}
     \documentclass[ class=scrbook,
     convert=false,
     border=0pt,% no borders
     ]{standalone}
     % if axis option " only scale axis" is used border has to be set manually to avoid cropping of the Y-Axis Label. Including the standalone then has to be set to \standaloneconfig{mode=tex}
     % Using border={0pt 0pt 0pt 0pt} seems not to work with scrbook

     % This KOMA options are needed to calculate the Textwitdh and Height
     \KOMAoptions{fontsize=12pt} % Fontsize

     % the textwidth of the main docement is 16cm=455.24945pt
     \newcommand{\originalTextWidth}{455.24945pt}
     \newcommand{\originalTextHeight}{591.53027pt}

     \usepackage{pgfplots}

     % Option that should not be change by the user, this are set here so it is obvious and makes the code more readable
     \pgfplotsset{
        every axis/.append style={
            width=0.75*\originalTextWidth,
            height=0.1*\originalTextHeight,
            scale only axis, % the width and height specifies only axis not the labels etc. to avoid missplacing of the different plots when Labels are used or not.
        },
     }
     \tikzset{every picture/.style={trim axis left, trim axis right}}% used to avoid missplacing of different plots when the numbers on the x-axis stands out left or right.

     \begin{document}%
        \makebox[\dimexpr\originalTextWidth\relax]{% Box to avoid problem of standalone cropping too much of the plot.
            \begin{tikzpicture}
            \begin{axis}[
            xlabel={Some Data},
            ylabel={Some Value},
            ]
            \addplot[very thick, red, mark=x] coordinates {(0,0)
                (1,2)(2,3)
                (3,4)(4,6)
                (5,11)(6,20)
                (7,15)(8,12)
                (9,8)(10,7)
                (11,3)(12,0)};
            \end{axis}
            \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);%
            \end{tikzpicture}% Never Remove this comment to avoid missplacing plot shifts to left side a little bit
        }%End \makebox
     \end{document}
\end{filecontents*}

\documentclass[]{scrbook}
 \usepackage{showframe}% to show the page layout
 \usepackage[textwidth=455.24945pt]{geometry} % 455.24945pt=160.00000mm not cm because of accuracy


 \usepackage{pgfplots} % loads tikz which loads xcolor and graphicx
 \pgfplotsset{compat=newest}

 \newcommand{\originalTextWidth}{455.24945pt}
 \newcommand{\originalTextHeight}{591.53027pt}

 % Option that should not be change by the user, this are set here so it is obvious and makes the code more readable
 \pgfplotsset{
    every axis/.append style={
        width=0.75*\originalTextWidth, 
        height=0.1*\originalTextHeight,
        scale only axis, % the width and height specifies only axis not the labels etc. to avoid missplacing of the different plots when Labels are used or not.
    },
 }
 \tikzset{every picture/.style={trim axis left, trim axis right} }% used to avoid missplacing of different plots when the numbers on the x-axis stands out left or right.
 %\setlength{\abovecaptionskip}{0pt}

 \usepackage{standalone}
 \standaloneconfig{mode=build}
 % tex = use sourcefile, default
 % image = use existing image file produced by the source file
 % build = build image from source, then use it
 % buildmissing= only build image if it does not exist
 % buildnew = only build image if source file is newer 

\setlength{\abovecaptionskip}{0pt} % just to show the difference

 \begin{document}

    \begin{figure}[!ht]
        \centering
        \begin{tikzpicture}
        \begin{axis}[
        xlabel={Some Data},
        ylabel={Some Value},
        ]
        \addplot[very thick, red, mark=x] coordinates {(0,0)
            (1,2)(2,3)
            (3,4)(4,6)
            (5,11)(6,20)
            (7,15)(8,12)
            (9,8)(10,7)
            (11,3)(12,0)};
        \end{axis}
                \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);%
        \end{tikzpicture}
        \caption{A plot in the Document} 
    \end{figure}
    \begin{figure}[!ht]
        \centering
        \includestandalone{standalone_plot_2}
        \caption{With Box and x-label but too much whitspace}
    \end{figure}    
    \begin{figure}[!ht]
        \centering
        \includestandalone{standalone_plot_1}
        \caption{With Box and x-label but too much whitspace}
    \end{figure}


 \end{document}

EDIT: Changed the picture and the code. As you can see the height of the zero is changed. And one thing also changed the distance off the y-label, what i appreciate because it makes all labels placed at the same place if the numbers on the y-axis don`t get to big.

3
  • \begin{tikzpicture}[every node/.style={inner sep=1pt,font=\tiny}] will save you some size. Jun 2, 2016 at 14:28
  • Yes that would save some space but also changes the distance of the numbers to the a axis and different things what i don't think is right. You can see the difference in the second graph above.
    – josarn
    Jun 2, 2016 at 14:41
  • a good solution for the space is provided tex.stackexchange.com/questions/312720/…
    – josarn
    Jun 2, 2016 at 15:54

1 Answer 1

1

Your standalone file uses fontsize=12pt while the main document uses KOMA's default which is 11pt. So the letters and numbers must be larger with mode=build than with mode=tex.

The value of compat should be the same in both the main and the standalone file. But you forgot \pgfplots{compat=newest} in the standalone file. If there is no compat set the default value for this option is used which is nearly the same as pre 1.3. That is the reason why there is more space between the ticklabels and the axis labels if mode=build is used with your MWE.

So in the following example I set

  • fontsize=12pt and
  • \pgfplotsset{compat=newest}

in the main document and in the standalone file.

Note that I use the same plot in both files and mode=build to show that there is no difference between the plots.

enter image description here

Code:

\begin{filecontents*}{standalone_plot_1.tex}
\documentclass[ class=scrbook, 
convert=false,
border=0pt,% no borders
]{standalone}
% if axis option " only scale axis" is used border has to be set manually to avoid cropping of the Y-Axis Label. Including the standalone then has to be set to \standaloneconfig{mode=tex}
% Using border={0pt 0pt 0pt 0pt} seems not to work with scrbook

% This KOMA options are needed to calculate the Textwitdh and Height
\KOMAoptions{fontsize=12pt} % Fontsize

% the textwidth of the main docement is 16cm=455.24945pt
\newcommand{\originalTextWidth}{455.24945pt}
\newcommand{\originalTextHeight}{591.53027pt}

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

% Option that should not be change by the user, this are set here so it is obvious and makes the code more readable
\pgfplotsset{
    every axis/.append style={
        width=0.75*\originalTextWidth, 
        height=0.1*\originalTextHeight,
        scale only axis, % the width and height specifies only axis not the labels etc. to avoid missplacing of the different plots when Labels are used or not.
    },
}
\tikzset{every picture/.style={trim axis left, trim axis right}}% used to avoid missplacing of different plots when the numbers on the x-axis stands out left or right.

\begin{document}%   
    \makebox[\dimexpr\originalTextWidth\relax]{% Box to avoid problem of standalone cropping too much of the plot.  
        \begin{tikzpicture}
        \begin{axis}[
        xlabel= Some Data,
        ylabel=Some Value,
        ]%
        \addplot[blue, mark=x] coordinates {(0,0)
            (1,2)(2,3)
            (3,4)(4,6)
            (5,11)(6,20)
            (7,15)(8,12)
            (9,8)(10,7)
            (11,3)(12,0)};
        \end{axis}
        \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);%
        %\clip[use as bounding box] (0,0.5)++(current bounding box.south west) rectangle (current bounding box.north east);%
        %\clip[use as bounding box] (0,0)++(.01\textwidth,.01\textwidth) rectangle ++(.45\textwidth,.45\textwidth);
        \end{tikzpicture}% Never Remove this comment to avoid missplacing plot shifts to left side a little bit
    }%End \makebox
\end{document}
\end{filecontents*}


\documentclass[fontsize=12pt]{scrbook}
 \usepackage{showframe}% to show the page layout
 \usepackage[textwidth=455.24945pt]{geometry} % 455.24945pt=160.00000mm not cm because of accuracy


 \usepackage{pgfplots} % loads tikz which loads xcolor and graphicx
 \pgfplotsset{compat=newest}

 \newcommand{\originalTextWidth}{455.24945pt}
 \newcommand{\originalTextHeight}{591.53027pt}

 % Option that should not be change by the user, this are set here so it is obvious and makes the code more readable
 \pgfplotsset{
    every axis/.append style={
        width=0.75*\originalTextWidth, 
        height=0.1*\originalTextHeight,
        scale only axis, % the width and height specifies only axis not the labels etc. to avoid missplacing of the different plots when Labels are used or not.
    },
 }
 \tikzset{every picture/.style={trim axis left, trim axis right} }% used to avoid missplacing of different plots when the numbers on the x-axis stands out left or right.
 %\setlength{\abovecaptionskip}{0pt}

 \usepackage{standalone}
 \standaloneconfig{mode=build}
 % tex = use sourcefile, default
 % image = use existing image file produced by the source file
 % build = build image from source, then use it
 % buildmissing= only build image if it does not exist
 % buildnew = only build image if source file is newer 

\setlength{\abovecaptionskip}{0pt} % just to show the difference

 \begin{document}

    \begin{figure}[!ht]
        \centering
        \begin{tikzpicture}[trim axis left,trim axis right]
        \begin{axis}[
        scale only axis,
        width=0.75\textwidth, 
        height=0.1\textheight,
        xlabel={Some Data},
        ylabel={Some Value},
        ]
        \addplot[very thick, red, mark=x] coordinates {(0,0)
            (1,2)(2,3)
            (3,4)(4,6)
            (5,11)(6,20)
            (7,15)(8,12)
            (9,8)(10,7)
            (11,3)(12,0)};
        \end{axis}
                \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);%
        \end{tikzpicture}
        \caption{A plot in the Document} 
    \end{figure}

    \begin{figure}[!ht]
        \centering
        \includestandalone{standalone_plot_1}
        \caption{With Box and x-label but too much whitspace}
    \end{figure}
 \end{document}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .