7

enter image description here

I am making some questions for my students involving pressure calculations of varying sized boxes.

As you can see, the varying sized pictures mean that the formatting of my table changes each time, ruining the alignment.

Is there a way that I can make each of these tikz pictures take up a fixed amount of room, without scaling the size of the cuboids themselves?

In other words, I want to create a fixed size "frame" or bounding box around each cuboid, with the cuboid sitting within that frame.

  • please add a minimal working example (MWE) – user36296 Nov 5 '17 at 12:09
  • 1
    You could draw an invisible rectangle of the same size around your block, \path (0.1,0.1) rectangle (2.1,2.12);. As long as this rectangle is bigger then all your components, it will determine the size of the bounding box. – user36296 Nov 5 '17 at 12:11
8

Something as simple as adding a \path between the two corners you want to be the bounding box will do the trick as long as the rest of your image is contained within that.

A better approach may be to explicitly fix the size of the bounding box with \useasboundingbox macro, which can give explicit coordinates, or coordinates relative to another tikzpicture as described in this answer. This will prevent the bounding box from expanding if something is placed outside the bounding box, which may or may not be desirable.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\node at (2,2) {Foo};
\draw (current bounding box.north east) -- (current bounding box.north west) -- (current bounding box.south west) -- (current bounding box.south east) -- cycle;
\end{tikzpicture}

\begin{tikzpicture}
\path (0,0) -- (5,5);
\node at (2,2) {Foo};
\draw (current bounding box.north east) -- (current bounding box.north west) -- (current bounding box.south west) -- (current bounding box.south east) -- cycle;
\end{tikzpicture}

\begin{tikzpicture}
\useasboundingbox (0,0) rectangle (5,5);
\node at (2,2) {Foo};
\node at (7,2) {Bar};
\draw (current bounding box.north east) -- (current bounding box.north west) -- (current bounding box.south west) -- (current bounding box.south east) -- cycle;
\end{tikzpicture}
\end{document}

enter image description here

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.