[Tex/LaTex] standalone tikz – proper size to include

size;standalonetikz-pgf

I am drawing my graphics for an article with tikz. For reasonable compilation speed I always draw the graphs as a standalone document and then include the graphic.

My question is now, how to figure out the right size in standalone. Of course, I don't want my graphic to be to big for my pages. Scaling it always messes up the layout to some degree.
Is there a recommended way to do it? Or at least the possibility to show some A4 box to be able to “guess'' the proper size?

Minimum example:

\documentclass[crop,tikz]{standalone}

\begin{document}
\begin{tikzpicture}
    \draw (0,0) circle (10);
\end{tikzpicture}
\end{document}

How do I e.g. know how big I can make this circle, before I have to re-scale my picture to fit it on a page?

Best Answer

You could use option class=scrartcl to change the underlying class to your neeeds. Then add all options needed by KOMA-Script package typerarea to calculate the page layout, e.g. DIV, BCOR, headinclude, fontsize etc.

Note that class standalone changes \textheight. So you have to use \storeareas and \recalculatetypearea to get the KOMA-Script \textheight. This must be saved in a macro before the standalone layout settings are restored.

Then it is possible to add e.g. a red rectangle showing the size of the text area of the KOMA-Script document. In the following example the upper left corners of the TiKZ picture and the red rectangle are aligned.

\documentclass[
  tikz,
  class=scrartcl,% underlying class which is loaded by standalone
  headinclude,fontsize=12pt,% options used by typearea
]{standalone}

\storeareas\standalonelayout% save the standalone layout
\recalctypearea% recalculate the typearea layout
\edef\savedtextheight{\the\textheight}% save the text height of the typearea layout
\standalonelayout% restore the standalone layout

% draw a red rectangle aligned with the upper left corner of the TikZ picture
% to show the size of the text area in the KOMA document:
\tikzset{
  every picture/.append style={
    execute at end picture={%
      \draw[red](current bounding box.north west)
        rectangle
        ++(\the\textwidth,-\savedtextheight);%
}}}

\begin{document}
\begin{tikzpicture}
    \draw (0,0) circle (10);
\end{tikzpicture}
\end{document}

Result:

enter image description here