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}
\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.