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. Commented 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
    Commented Jan 5, 2014 at 20:10
  • @Dror: Just remove the `\centering\usebox{\Image}` line...
    – Dror
    Commented Jan 5, 2014 at 20:48
  • Note that depth and height are different, see tex.stackexchange.com/questions/40977/… for example.
    – Tim
    Commented Feb 5, 2014 at 12:50
  • @YiannisLazarides Do you know whether a similar approach would be possible for tikz images?
    – Karlo
    Commented Oct 6, 2023 at 8:59
  • 1
    @Karlo YOu can use a similar approach, just place the tikz code in a box and measure it, although I think you will be able to also get it through TikZ as the bounding box. Why dont you ask the question and I am sure someone will answer.
    – yannisl
    Commented Oct 7, 2023 at 11:24

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! Commented 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
    Commented 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! Commented 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

  • Very nice work.
    – internet
    Commented Dec 10, 2022 at 13:53
  • Fantastic! Works great!
    – Tropilio
    Commented Aug 8, 2023 at 15:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .