# Resizing a standalone pdf-file with \geometry results not in the correct size or content is shifted

I want to externalize my tikz-picture in a standalone class. Because I am using relative measures as \textwidth I need my standalone-file to match excatly the dimensions as my main.tex is.

Looking here the geometry package seems right for this. However, even with and without the 'pass' option the resulting picture has the wrong size or is being shifted inside the croppes area.

MWE:

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{layouts}
\usepackage[paperwidth=20cm]{geometry}  % add 'pass' stillt not work
\pgfplotsset{compat=1.16, width= .8\textwidth}

\begin{document}
PaperWidth in [cm] \printinunitsof{cm}\prntlen{\paperwidth}
\begin{tikzpicture}
\begin{axis}
\addplot [] coordinates {(0,0) (1,2) (2,3)};
\end{axis}
\end{tikzpicture}
PaperWidth in [cm] \printinunitsof{cm}\prntlen{\paperwidth}
\end{document}


Without 'pass' picture not completely shown and wron size:

With 'pass' picture not completely shown but better and even smaller (80% of 21cm is not 8.8):

• Remove the class option tikz and maybe add crop=false etc. By default standalone crops to the picture size. (It may even use geometry.) You've got conflicting instructions here so, unsurprisingly, things get messed up. – cfr Aug 27 '18 at 18:35
• It would help to know what you want the result to be and how you're using this file. Are you compiling it and then including it as an external image or are you \inputting it in a main file? – cfr Aug 27 '18 at 18:42
• I try deleting [tikz], this help a little, however when using this: \usepackage[pass,paperwidth=18cm]{geometry} and print out the textwidth it is saying still 21.59cm – SRel Aug 27 '18 at 18:46
• In addition to @cfr 's comment, do you use the externalize library of pgf-tikz ? – BambOo Aug 27 '18 at 18:49
• Why don't you just set the relevant width in the setting for PGF plots? You're hard-coding it anyway, so it isn't any less flexible. As long as it is only in the preamble, it won't affect the final version. I don't understand the obsession with setting \textwidth. But, if you really must, just set it. I wouldn't bother with geometry  etc. unless, of course, you want to see the plot as it will be on a full page. That would be different, obviously. – cfr Aug 27 '18 at 23:49

Too long for a comment so my apologies in advance. Happy to delete if it is not relevant.

In general, when I want to have external plots, I follow this strategy.

I start with creating a FigureHeader.tex file containing set of parameter instructions

% some useful  packages
\usepackage{...}
....
% some useful libraries
\usetikzlibrary{...}
% Some personal styles/options
\tikzset{myaxis/.style={width=20cm,...}}


this way you can define a lot of parameters in the same parameter file, so if you have a lot of repeating graphics, it's easier to do this than to rewrite everything all the time.

Then in the image file do

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\begin{axis}[myaxis]
...
\end{axis}
\end{tikzpicture}
\end{document}


Then, in the main document, I simply input the figure with \includegraphics{theimage.pdf}

• yes I am doing this nearly the same, using a precompiled file which contains all used packages for the graphics and a shared preamble for some style definitions so everyplot looks the same – SRel Aug 27 '18 at 18:54
• Cool, so not totally irrelevant. What do you mean by a precompiled file ? – BambOo Aug 27 '18 at 18:57
• I precompiled the static part of the preamble like loading the Tikz-packages etc following this manual: link so that i nearly receive a live preview (compiling of the picture does take about 2senconds now) – SRel Aug 27 '18 at 19:00