How to make a bounding box around overpic that includes the added contents (such as \put, etc.)?

For instance below \fbox does not take into account the \put commands nor the grid labels.


    \put(45,20){\textcolor{red}{blah blah right}}
    \put(20,30){\rotatebox{90}{\textcolor{red}{blah blah top}}}


enter image description here

  • 1
    By design and as explained in the documentation, the environment has the same dimensions as the included image, so you will need to tell \fbox how much bigger you want it to be, if you do it this way. (Or change the way the environment works, of course.) I don't understand why you'd do this with overpic as it doesn't seem suitable for your needs. With something like TikZ, you could do it straightforwardly, but you want to tighten your screws with a pencil sharpener, so life is obviously going to be tricky. – cfr Dec 22 '17 at 0:56
  • @cfr "life is obviously going to be tricky": sorry it was not obvious to me. I'll go with tikz. – anderstood Dec 22 '17 at 3:23
  • 1
    I was just going by what the documentation for overpic says. It is only about 3 pages long with plenty of pictures, so a pretty quick read. – cfr Dec 22 '17 at 4:48

As the documentation says, the dimensions of the overpic environment are the dimensions of the included image. By design, it does not do what you want. Hence it would be better to use something more amenable to your desiderata or, alternatively, to change your desiderata. Since people are usually more open to the former than the latter, I suggest a solution in this vein.

This is relatively straightforward in TikZ, though not entirely so as the use of dimensions rather than a relative scale makes this a bit more complex. Still, it is very doable in TikZ.

    \node [inner sep=0pt, fill=gray] (img) {\includegraphics[width=.9\linewidth]{tiger}};
    \draw [orange] (current bounding box.south east) rectangle (current bounding box.north west);
    \begin{scope}[shift=(img.south west)]
      \foreach \i in {0,10,...,\mywidth} \node [anchor=north] at (\i mm,-2.5pt) {\i};
      \foreach \i in {0,10,...,\myheight} \node [anchor=east] at (-2.5pt,\i mm) {\i};
      \draw [red] (current bounding box.south east) rectangle (current bounding box.north west);
      \node [red, font=\large\sffamily\bfseries] at (110mm,60mm) {Roar!};
      \node [magenta, font=\LARGE\sffamily\bfseries] at (75mm,115mm) {Tiger, tiger in the night \dots};
    \draw [blue] (current bounding box.south east) rectangle (current bounding box.north west);

The \draw lines are just there to indicate the bounding box at various points during the picture's construction. The thin outer line in black is, of course, the \fbox rule.

Tiger, tiger ...

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.