TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm drawing a number of very similar images using tikz, like this:

enter image description here

Code (and motivation) are given at Making cards for Magic: The Gathering and similar card games.

Compilation is slow. I've timed it, and most of the time is being spent repeatedly drawing the same image, in this case

enter image description here

It seems to me that there should be some way to save this material once it is rendered, to prevent the duplication of work. Is it possible to reuse a part of a tikz image points me in a sensible direction, in that it suggests using a box. My problem is that I have no idea how to get the text to be placed sensibly relative to the material saved in a box... .

share|improve this question
You can look in to the pic facility of tikz, I hope. – Harish Kumar Jun 15 '14 at 13:25
Thanks! In case anyone else is reading this: texample.net/tikz/examples/tree-pic – Mohan Jun 15 '14 at 13:36
@Harish Kumar: From the 3.0.0 manual, it seems as if the material is redrawn every time. Are you sure pic is faster? – Mohan Jun 15 '14 at 13:46
tex.stackexchange.com/questions/837/… It might be possible to reuse the image as a background image as suggested here? – srao Jun 15 '14 at 14:13

This assumes that saveboxes are faster than macros. It should be remembered that the savebox is larger than the text area inside.


%create border around empty text area 4cm by 2cm

\node[draw=red, thick] {\parbox[t][2cm]{4cm}{\strut}};


% align edges

\path (0,0) node[inner sep=0] (border) {\usebox{\myborder}}
  (border.north west) node[below right] {\begin{minipage}{4cm}
  With any luck this text will fit nicely into the borders drawn previously.

% align centers

\path (0,0) node[inner sep=0] {\usebox{\myborder}}
  (0,0) node {\parbox[t][2cm]{4cm}
  {With any luck this text will fit nicely into the borders drawn previously.}};


aligned border

share|improve this answer
"savebox is larger than the text area inside": due to outer sep? – Mohan Jun 15 '14 at 20:20
Actually, the inner sep and line thickness. But it is worse than that. Further tests with registration marks showed that even when both nodes are centered, the second node is 1.5pt left of the first. – John Kormylo Jun 15 '14 at 20:59
Aha! I needed a % after { to prevent adding an extra space. – John Kormylo Jun 15 '14 at 21:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.