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 need 2 different TikZpictures with the same bounding box (the one of the first TikZpicture) because I need a perfect vertical alignment of the subfigures side by side.

Please, how can I handle this?

share|improve this question
Note that it is unusual around here to sign your questions (as there is already a box with your username below it) or to have any greeting. – lockstep Mar 2 '11 at 15:48
up vote 9 down vote accepted

You can use the \useasboundingbox command in the second picture to set the bounding box. Should be the first command in the picture.

\useasboundingbox (0,0) rectangle (<width of first picture>,<height of first picture>);

If you don't know the dimensions of the first picture you can get them from the current bounding box node. Using remember picture you can then access this information in the second node.

The code below will set the accept same bounding box for the second picture.

   \draw (-1,-1) -- (5,5);
   % more drawing commands ...
   \coordinate (FIRST NE) at (current bounding box.north east);
   \coordinate (FIRST SW) at (current bounding box.south west);
   \useasboundingbox (FIRST SW) rectangle (FIRST NE);
   \draw (0,0) -- (1,1);

This works if both pictures use only positive coordinates. Adjustment must be made if this isn't the case.

The \fbox commands are only to display the bounding box and are not really required.

share|improve this answer
Now I know how to use pgf to avoid \newbox :) but you need to compile twice. – Alain Matthes Mar 2 '11 at 16:05
@Martin: The result is incorrect for me, the second line is out of the second box ? – Alain Matthes Mar 2 '11 at 16:11
@Altermundus: You don't need to compile it twice. It works fine in the first run. Maybe you are confusing remember picture with overlay? – Martin Scharrer Mar 2 '11 at 16:15
@Altermundus (and Martin): It seems this solution only works correctly on the first compile. Compiling it again moves the short line down. Removing [remember picture] makes it work, though. Funny... – Jake Mar 2 '11 at 16:15
@Jake,Altermundus: I updated my example to the simple version I had before. It only works for positive coordinates, but shows that the principle works. – Martin Scharrer Mar 2 '11 at 16:18

Another way to do it is to use a single tikzpicture environment and one scope environment:

% TikZ code for first picture
% TikZ code for second picture

Then the points plotted at (x,y) in each scope will be exactly 5cm apart.

share|improve this answer

The code of Martin is correct but if you want to know the width and the height of the picture, you can use


Now you get the width and the height of picture with


The height is \dp + \ht. I don't know if pgf/TikZ gives the height and the width directly.

share|improve this answer

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.