Suppose I have a figure in my LaTeX document:


My question is pretty simple: Is there a way to get the size that some_graphic will be rendered to in points/inches/whatever unit into a variable for use in the rest of the document? Here's a slightly more reasonable motivating example from beamer:

  \begin{block} \begin{block}<2->{Title}
    Text on the first part.
    \vspace{2.19in}  % Would be nice not to have to tweak this value manually
      \includegraphics[width=0.60\textwidth,clip,trim=0in 2.1in 0in 0in]{figures/scheme}
    \vspace{0.775in} % Would be nice not to have to tweak this value manually

In other words, I realize that there is a way around this problem manually, by tweaking the vspace values, but that's not very reasonable, and it seems to go against the whole idea behind TeX of letting the rendering engine do the work.

4 Answers 4


The literal method for doing this looks something like as follows:


% OR: \settoheight\graphicheight{\mygraphic}
\mygraphic % to insert the graphic
\vspace{\graphicheight} % whitespace same size as the graphic

But there is also the \phantom command which creates an empty box of the same size as its contents, which might suit your specific circumstances better:

\mygraphic % insert the graphic
\phantom{\mygraphic} % insert a blank box of the same size

Additionally, \includegraphics takes a draft option to replace individual images by placeholders, so


might perform better than including the actual image.

  • Thanks, Will. An excellent answer, as always. I've been wanting to know how to do this ever since I first used the \includegraphics command. Oct 4, 2010 at 13:48

This is a solution that I have recently developed to measure the dimensions of an image






   % create and save the box
  % Set graphics to fixed size for this example
  \savebox{\Image}{\includegraphics[width=80pt, height=120pt]{#1}}
      The height of the image (#1) is : \the\imageh\\
     The width of the  image (#1) is : \the\imagew\\
     The depth of the  image (#1) is : \the\imaged\\}


It renders as shown below. There are three dimensions shown (width, height and depth)

Example render of measuring picture dimensions

  • Is there a way to save the information into dimensions variables without inserting the picture at all? Not as a phantom, or anything like that.
    – Dror
    Jan 5, 2014 at 20:10
  • @Dror: Just remove the `\centering\usebox{\Image}` line...
    – Dror
    Jan 5, 2014 at 20:48
  • Note that depth and height are different, see tex.stackexchange.com/questions/40977/… for example.
    – Tim
    Feb 5, 2014 at 12:50

If this is for beamer, an alternative solution might be to look into the \begin{overlayarea} command which should allow you to replace one figure with another while keeping the text outside the overlayarea unmoved. See page 79 et seq. of the beamer user guide.

  • I've always wanted to know how to do this. Thanks! Oct 1, 2010 at 16:26
  • overlayarea is not especially user friendly, but for simple stuff, like what the OP seems to want, it's fairly good.
    – Seamus
    Oct 3, 2010 at 15:26
  • In this specific case, your answer probably works better, even if it isn't the answer to the general question. Thanks for the help! Oct 4, 2010 at 13:50

Inspired by this answer of Martin Scharrer♦ I would say that you can use the package adjustbox in order to get these dimensions.

The key features are related to gstore and you can use the measurements to solve your problem.

Here is an example:


\newlength\myHeight % creating lenghts


    \adjustbox{gstore width=\myWidth, gstore height=\myHeight, center}{

Height: \the\myHeight % print Height

Width: \the\myWidth % print Width


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.