# Edges of tikz picture cut off when using shifted scope

I'm drawing a standalone tikz picture and when I compile it one of the edges is cut off. I think it's because I'm using a shifted scope within the picture. (Edit, it may be due to the [x=2cm,y=2cm] scale I have applied to the picture)

\documentclass[tikz,varwidth,border=5pt]{standalone}
\begin{document}
\begin{tikzpicture}[x=2cm,y=2cm]
\begin{scope}
\draw (0,0) rectangle (3,3);
\end{scope}

\begin{scope}[shift={(3.5,0)}]
\draw (0,0) rectangle (3,3);
\end{scope}
\end{tikzpicture}
\end{document}


The furthest right part of my picture is being cut off, I suspect the varwidth, border=5pt] arguments aren't taking the shift (edit: or maybe the scale) into account.

So my question is either:

• Is there a non-manual way of making sure the edges of my picture don't get cut off? (I'm aware of \useasboundingbox but would prefer not to use it)
• Is there a better technique than shift to construct two pictures which are very similar but offset from one another by some amount? I don't want to have to draw the picture twice with different coordinates. From an editing point of view shift is much more efficient.
• Can you make an example that actually demonstrates the problem? Adding something like \draw (0,0) rectangle (1,1); in both scopes isn't enough. For the second part you could have a look at using \pics. See chapter 18 in the manual, or the tikz-pic tag here on the site. – Torbjørn T. Sep 25 '17 at 15:55
• @TorbjørnT. I've replicated the problem but it might be due not to the shift but due to a scaling of the whole picture I have: \begin{tikzpicture}[x=2cm,y=2cm]. Now the problem is there when the shift is {3.5,0} and the rectangles are (3,3) large. – thosphor Sep 25 '17 at 16:12
• @user3087409 please edit your post and place the code so that we can just copy paste. – koleygr Sep 25 '17 at 16:14
• Why are you using varwidth anyway, if you all you have is a tikzpicture it's pointless? (And apparently the cause of the problem.) – Torbjørn T. Sep 25 '17 at 16:15
• I answered. Might as well keep it around, no need to delete I think. – Torbjørn T. Sep 25 '17 at 16:21

The problem is varwidth, which in the example you show is completely unnecessary, so just remove it.
With varwidth, the content is set in a varwidth environment that is \linewidth wide. By default, \linewidth corresponds to about 12cm. The content in your diagram is 7.5 * 2 = 14cm wide, so you get an Overfull \hbox (25.28575pt too wide). Because standalone sets the size of the PDF to that of the varwidth, part of the diagram is cut off.