Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
1  
You can look in to the pic facility of tikz, I hope. –  Harish Kumar Jun 15 at 13:25
    
Thanks! In case anyone else is reading this: texample.net/tikz/examples/tree-pic –  Mohan Jun 15 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 at 13:46
1  
tex.stackexchange.com/questions/837/… It might be possible to reuse the image as a background image as suggested here? –  srao Jun 15 at 14:13

1 Answer 1

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

\documentclass{article}
\usepackage{tikz}

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

\newsavebox{\myborder}
\savebox{\myborder}{%
\begin{tikzpicture}
\node[draw=red, thick] {\parbox[t][2cm]{4cm}{\strut}};
\end{tikzpicture}}

\begin{document}

% align edges

\begin{tikzpicture}
\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.
  \end{minipage}};
\end{tikzpicture}

% align centers

\begin{tikzpicture}
\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.}};
\end{tikzpicture}

\end{document}

aligned border

share|improve this answer
    
"savebox is larger than the text area inside": due to outer sep? –  Mohan Jun 15 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 at 20:59
    
Aha! I needed a % after { to prevent adding an extra space. –  John Kormylo Jun 15 at 21:14

Your Answer

 
discard

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.