I'm having a strange behavior whithin my tex document. I have a large project of several tex files. For my tikz pictures I use the standalone document class and include them via
\begin{figure}[!ht]
\centering
\includestandalone[mode=buildnew, width=1.0\textwidth]{tikzPicture}
\caption{caption}
\label{fig:tikzPicture}
\end{figure}
The issue is, that the pictures get smaller than \textwidth and if I try to scale them with scale=1.5 instead of width=1.0\textwidth they get left shifted and are not centered any more.
One of my tikz pictures looks like following:
\documentclass{standalone}
\usepackage{graphics}
\usepackage{tikz}
\usepackage{tikzscale}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\usepackage{etoolbox}
\usepackage{ifthen}
\usepackage{rotating}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{10pt}
\usetikzlibrary{shadows}
\usetikzlibrary{arrows,shapes}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\xdefinecolor{midnightBlue}{RGB}{25,25,112}
\xdefinecolor{navy}{RGB}{0,0,128}
\xdefinecolor{fireblick}{RGB}{178,34,34}
\begin{document}
\begin{tikzpicture}[
scale=1,
node distance=0mm,
desc/.style={
rectangle,
rounded corners,
draw=black,
very thick,
text centered,
text width=7cm,
minimum height=12mm,
fill=midnightBlue!30,
drop shadow
},
hByte/.style={
rectangle,
rounded corners=1pt,
draw=black,
thick,
text centered,
text width=0.6cm,
minimum height=28mm,
fill=midnightBlue!30,
xshift=0.45cm,
drop shadow
},
Byte/.style={
rectangle,
rounded corners=1pt,
draw=black,
thick,
text centered,
text width=0.6cm,
minimum height=56mm,
fill=midnightBlue!30,
xshift=0.45cm,
drop shadow
},
qByte/.style={
rectangle,
rounded corners=1pt,
draw=black,
thick,
text centered,
text width=2.6cm,
minimum height=10mm,
fill=midnightBlue!30,
xshift=1.45cm,
drop shadow
},
it/.style={
fill=blue!10
},
level1/.style={
minimum height=5mm,
text width=10cm,
text centered
},
every node/.style={font=\sffamily}
]
\node at (0cm,0cm) [] (base) {};
%-------------------------------------------------------------------
%draw level 1
\node at ($(base)+(-7cm,3cm)$) [desc, it, text width =4.7cm, xshift=2.5cm] (header) {...};
\node at ($(header.east)-(0cm,0cm)$) [desc, it, text width =6.7cm, xshift=3.5cm] (body) {timeSource};
\node at ($(body.east)-(0cm,0cm)$) [desc, it, text width =2.7cm, xshift=1.5cm] (tlv) {path trace TLV};
%-------------------------------------------------------------------
%draw segments
\def\arrowOffsetOne{0cm,2cm};
\def\arrowOffsetTwo{0cm,1cm};
\draw [darkgray,thin,<->] ($(header.north west)+(\arrowOffsetOne)$) -- ($(tlv.north east)+(\arrowOffsetOne)$) node [black,level1, midway, above=0.1cm] (frame) {Announce Nachricht};
\draw [darkgray,thin,<->] ($(header.north west)+(\arrowOffsetTwo)$) -- ($(header.north east)+(\arrowOffsetTwo)$) node [black,level1, midway, above=0.1cm] (headerLength) {29 Byte};
\draw [darkgray,thin,<->] ($(body.north west)+(\arrowOffsetTwo)$) -- ($(body.north east)+(\arrowOffsetTwo)$) node [black,level1, midway, above=0.1cm] (bodyLength) {1 Byte};
\draw [darkgray,thin,<->] ($(tlv.north west)+(\arrowOffsetTwo)$) -- ($(tlv.north east)+(\arrowOffsetTwo)$) node [black,level1, midway, above=0.1cm] (tlvLenght) {\textgreater
4 + 8N Byte};
%-------------------------------------------------------------------
%draw Header
\node at ($(base)+(-5cm,-3cm)$) [qByte, it, fill=orange!20] (node1) {tlvType};
\node at ($(node1.east)-(0.025cm,0cm)$) [qByte, it, fill=red!20] (node2) {lengthField};
\node at ($(node2.east)-(0.025cm,0cm)$) [qByte, it, fill=green!20] (lastnode) {pathSequence};
%-------------------------------------------------------------------
%draw separating lines
\draw [gray,dashed,thin] ($(header.north west)+(\arrowOffsetOne)+(0cm,1cm)$) -- (header.south west);
\draw [gray,dashed,thin] (tlv.south west) -- (node1.north west);
\draw [gray,dashed,thin] ($(body.north west)+(\arrowOffsetTwo)$) -- (body.south west);
\draw [gray,dashed,thin] ($(body.north east)+(\arrowOffsetTwo)$) -- (body.south east);
\draw [gray,dashed,thin] ($(tlv.north east)+(\arrowOffsetOne)+(0cm,1cm)$) -- (tlv.south east);
\draw [gray,dashed,thin] (tlv.south east) -- (lastnode.north east);
\draw [gray,dashed,thin] (node1.south west) -- ($(node1.south west)-(0,0.3)$);
\draw [gray,dashed,thin] (node1.south east) -- ($(node1.south east)-(0,0.3)$);
\draw [gray,dashed,thin] (node2.south east) -- ($(node2.south east)-(0,0.3)$);
\draw [gray,dashed,thin] (lastnode.south east) -- ($(lastnode.south east)-(0,0.3)$);
\node at ($(node1.south west)-(0.5,0.7)$) [black, level1] {Byte};
\draw [darkgray,thin,<->] ($(node1.south west)-(0,0.3)$) -- ($(node1.south east)-(0,0.3)$) node [black,level1, midway, below=0.1cm] {2};
\draw [darkgray,thin,<->] ($(node2.south west)-(0,0.2)$) -- ($(node2.south east)-(0,0.2)$) node [black,level1, midway, below=0.175cm] {2};
\draw [darkgray,thin,<->] ($(lastnode.south west)-(0,0.3)$) -- ($(lastnode.south east)-(0,0.3)$) node [black,level1, midway, below=0.1cm] {8N};
%-------------------------------------------------------------------
\end{tikzpicture}
\end{document}
Does anybody know what could cause this behavior? Regards, Efim
Solution: As esdd already told in his comment, the solution is very simple. The reason for that scaling issue was that the setting text width=10cm whithin level1 was enlarging the whole picture. Removing this setting solves the issue.

mode=imageinstead ofbuildnew. I thinkbuildnewuses the picture code andimageuses the produced Image. The difference is that tikzpictures do not have awidthoption but Images have... (I'm not sure, this is more of a hunch) – Guilherme Zanotelli Dec 12 '16 at 08:33width=\textwidth. If you make it wider than\textwidth(as happens withscale=1.5, as far as I can see), the image will stick out into the right margin, or even out of the page. If you want it centered on the textblock you can use\makeboxoradjustboxas discussed in http://tex.stackexchange.com/questions/39435, but modifying the diagram might be just as good a solution. – Torbjørn T. Dec 12 '16 at 08:38TikzEdtto verificate your Tikz code. Look the link: http://www.tikzedt.org/. – Sebastiano Dec 12 '16 at 08:39text width=10cmfor the stylelevel1enlarges your picture on the left and right side. So there is additional whitespace. Remove this setting forlevel1to get the desired result. – esdd Dec 12 '16 at 08:58