21

I used the following construct quite often:

\includegraphics[width=\textwidth/2]{pic.png}

But when I try to adjust the size a small bit, like this:

\includegraphics[width=\textwidth*0.45]{pic.png}

I get

! Package calc Error: `.' invalid at this point.

What am I doing wrong?

0

3 Answers 3

41

The calc package allows only division by integers or by reals which are announced as \real: so

\includegraphics[width=\textwidth*\real{0.45}]{pic}

will do, but

\includegraphics[width=0.45\textwidth]{pic}

works as well, doesn't require calc and is faster.

1
  • 1
    Thanks! I really should read a bit about TeX syntax - because this was not very obvious.
    – Rogach
    Apr 23, 2012 at 7:44
16

You can use

\includegraphics[width=0.45\textwidth]{pic.png}
8

Great "short" answers!

Just to expand into the general concept that will answer this question in a more understandable way:

Wherever you have a macro that expands into a length for instance: \parskip, \linewidth, ... Or in this case \textwidth you can create another length just by setting a floating point factor before the macro.

For example:

  • 0.78\parskip
  • 2\linewidth
  • ...

or in your case 0.45\textwidth

are valid values for the parameter width in includegraphics

You can take a look at the first lines of the wiki article: http://en.wikibooks.org/wiki/LaTeX/Lengths

You must log in to answer this question.

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