I've been using TikZ to draw graphs (pgfplots) and pictures for my physics courses etc.
Because I like it when (for example) the box of graph is centered on the page without looking at the stuff that comes with it (ylabel
, yticks
, etc.), I draw a rectangle on top of like this:
\draw[draw=none, use as bounding box](0,0) rectangle (\figurewidth,\figureheight);
This way only the the box of the graph is considered when the figure is to be placed on the page.
This approach works for me ad I've applied it many times. However, I seem to get in to trouble when using the externalize
library. Because the created external figures are cut off at the edges of the bounding box
, I lose all that's outside (without externalize
this wasn't happening, everything was drawn).
I can see two possible solutions to my problem:
-
Use another command that makes the centering correct, e.g.:
\draw[center on this, draw=none](0,0)rectangle(\figurewidth, \figureheight);
-
Tell the
external
package not to clip atbounding box
Any ideas?
Best Answer
You cannot use "real" bounding boxes with the
external
library, because of the problems you described. What you have to do instead is use thetrim left
,trim right
andbaseline
commands to shift the picture according to your requirements.From the pgfmanual, p. 168:
With
pgfplots
, you can very comfortably just use[trim axis left,trim axis right]
as options to thetikzpicture
environment.Other pictures can be centered by using
[trim left,trim right=0pt]
, for example, to essentially trim the picture down to a vertical line going through the origin.