I have the following image being produced with the following code:


entire tikzpicture figure centered






\usepackage{adjustbox}  % This is to scale the entire figure so it doesn't mess up the spy

        \item I'm talking about a figure. It's a great figure. Glorious, I might add\dots Here's the figure:
                \begin{tikzpicture}[spy using outlines={circle, magnification=3, connect spies}]
                        xlabel={Temperature ($\unit{\celsius}$)},
                        ylabel={Consumption (litres per hour)},
                        axis lines=left,
                        legend style={at={(0.5,-0.3)}, anchor=north},
                        tick align=center
                    \addplot[black, dotted, ultra thick, domain=15:105, samples=100] {(770 / x)-1.325};
                    \addplot[orange, dotted, ultra thick, domain=15:105, samples=100] {71.1 * exp((-0.0235)*x)};
                    \coordinate (spypoint) at (axis cs:102.5,6);
                    \coordinate (magnifier) at (axis cs:150,30);
                    \spy[gray, size=3cm] on (spypoint) in node[] at (magnifier);
        \hrule  % This is just to give perspective on how the figure is centered.
        See? I said it was glorious, didn't I?


What I really want is only for the graph (the axes) to be centered, but the spy to be uncentered (relative to the page).


1 Answer 1


Great figure!

If you add overlay to a TikZ scope, that scope bounding box (the physical space it occupies) is not considered when computing the graphic's size.

So writing

 \spy[gray, size=3cm,overlay] on (spypoint) in node[] at (magnifier);

Will give you

enter image description here

Notice that the "spilling out" of the graph from the border goes unnoticed because you asked to ignore it... so you have to take care not to have it going outside the page area.

  • Thanks for this! It works perfectly (I did have to adjust the adjustbox width parameter to 0.5\textwidth to make the figure display correctly). I've marked this as the answer. Commented Jun 1, 2023 at 8:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .