I've been reading through a number of answers that use \newsavebox to save the contents of a box. As far as I can tell it's a workaround for fragility of some kind. Is that right? If not, what is the point of saving a box?

  • 6
    Usually it is one of either for 1) measuring the dimenension of the content (for some later use; for example \phantoms), or 2) re-use the content multiple times (say, same header content on all pages). – morbusg Dec 16 '12 at 11:48
  • 2
    Further to @morbusg's comment, it is needed when you want to align the content and the alignment depends on the dimensions of the content as well as the dimensions of other, similar contents. For example, if you want to align m x n pictures inside a figure environment. – user10274 Dec 16 '12 at 12:50

Box usage isn't (normally) related to fragility. Boxes (and glue) are the fundamental typesetting constructs that TeX uses. All of TeX's typesetting is done by positioning boxes. Saving a box (as opposed to saving a command) means that you are saving a fragment of typeset text rather than saving a list of tokens to be executed. As mentioned in comments there are many reasons for wanting to do that. It might be to measure the width of some typeset construct, it might be that executing the commands is very costly in terms of execution time and you want to re-set copies of the same result multiple times, or it may just be that you want to pass a typeset fragment to another command (such as \fbox where it is more convenient to first set the contents into a box rather than directly as a command argument (perhaps because the contents involve verbatim material.)


i've used it to save and reuse a small graphic to replace the amsthm proof "tombstone":


relevant quote from the texbook (p.329):

It's much faster to copy a box than to build it up from scratch.


I can't name all of the situations to use a savebox but one particular case that I've found it very useful is for aligning subfigures


The idea is to save the largest image into a box, which you can then measure to help with the \vfill in the other subfigures. This allows the caption and the images to remain aligned as you wish.




% store the bigger of the pictures in a vbox
      \draw circle (1.25cm) {};

    % use the save box
    \caption{Biggest (using a savebox)}
    % for the other figures, you can use \vfill as follows
    \vbox to\ht\tempbox{
      \draw circle (.5cm) {};
    \caption{Top justified}
    % vertically centered
    \vbox to\ht\tempbox{
      \draw circle (.5cm) {};
    \caption{Vertically centered}


Mostly I use it to reuse parts of graphics inside the picture environment. An example is printing my business card:






\setkomavar{name}{Mrs. Example}
\setkomavar{street}{Some street 123}
\setkomavar{phone}{123 456 789}
\setkomavar{mobile}{987 654 321}



    \put(-42.5,0){\makebox(85,54){\shortstack[r]{\vspace{-3pt} \tiny www.\\ \tiny mail@}
        \large \usekomavar{name}
        \small .com}}
        \usekomavar{street}, \usekomavar{zip} \usekomavar{city}\\
        \usekomavar{phone}, \usekomavar{mobile}


% crop marks

% place ten cards on the page


See https://en.wikibooks.org/wiki/LaTeX/Picture#Multiple_Use_of_Predefined_Picture_Boxes for another example and explanations.

  • 3
    Can you give the details of your answer here? it is much better to include the instructions in the answer's body, as links may expire and render the post useless. – hpesoj626 Dec 16 '12 at 15:11
  • @hpesoj626 You're right, I added an example. – hielsnoppe Dec 17 '12 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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