If I write

\noindent\vskip 0ex plus 2ex\includegraphics[width={\textwidth plus 2pt minus 2pt}, angle=0]{J2-23-1}

it is correct

However, if I write

\noindent\vskip 0ex plus 2ex\includegraphics[width={\textwidth plus 0.02\textwidth minus 0.02\textwidth}, angle=0]{J2-23-1}

it said "missing number treated as zero".

However, if I included \usepackage[final]{pdfpages} even if I do not use it, the above error message disappeared.

Could anyone tell me what is wrong?

  • 1
    Welcome! Probably pdfpages loads calc. Does loading calc instead make the error go away? – cfr Apr 8 '16 at 3:10
  • What should \noindent\vskip 0ex plus 2ex do? – egreg Apr 8 '16 at 10:10
  • egreg: I have several images of roughly the width as the page width but with different height. LaTeX arranges them into pages. However, sometimes an image can fit into one page if it is slightly smaller/ or if the space between images can be slightly adjusted.......i.e. I am trying to make glue to both horizontal and vertical directions. Hope that explains what I am doing. – watv Apr 11 '16 at 11:10

A glue specification is not allowed as width or height in \includegraphics, it does not support flexible dimensions.

In the first case, plus 2pt minus 2pt goes into the output two times:

    width={\textwidth plus 2pt minus 2pt},


If package calc is used, then its \setlength internally uses a length register for assignment, thus the glue parts are read and consumed, but never used.

Also in the second case, the glue specifications are set as normal text (without package calc): plus 0.02 is text, then \textwidth is a register, which starts an assignment, but the following m is not valid number for a dimen assignment and causes the error message.

-> Avoid glue specifications in the options of \includegraphics. They do not have a purpose and are only causing trouble. Skip (length) registers can be used nevertheless, they are internally coerced to dimen registers ignoring the glue parts. This can be used as workaround, if the glue specifications cannot be avoided (coming from some user macros or whatever):

\includegraphics[width=\glueexpr(\textwidth plus ... minus ...)\relax, ...]{...}
  • Why in the first case "plus 2pt minus 2pt goes into the output two times"? Why two times? I did not see them in my output....perhapse covered by other images.... – watv Apr 11 '16 at 11:15
  • so..the conclusion is: I cannot use glue for includegraphics? – watv Apr 11 '16 at 11:17
  • @watv Yes. Graphics, boxes, ... require fixed dimensions. – Heiko Oberdiek Apr 11 '16 at 15:48
  • @watv The number of plus 2pt minus 2pt depends on the used options and the implementation. – Heiko Oberdiek Apr 11 '16 at 15:49
  • now I use \includegraphics[width=\glueexpr(\textwidth plus ... minus ...)\relax, ...]{...} and it works fine. But a question: why there is a "relax" at the very end? You said "Graphics, boxes, ... require fixed dimensions" but why can this work? – watv Apr 11 '16 at 21:06

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.