# scale in graphicx don´t work when width set with setkeys

I am editing a document using graphicx with width options set by setkey, as in

\setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio}


The problem is that when I want to specifically resize a picture with scale option, it does not work. Therefore

\includegraphics[scale=0.5]{anypic.png}


Has no effect at all. It seems to be overriden by the width.

There is any way to make graphicx forget the width for one specific figure?

Obs: resetting the width of the figure works, but I would like to avoid measuring figures.

• Why not width=0.5\linewidth? – jon Mar 7 '16 at 2:23
• What does 'measuring' mean? Do you want to 'scale' the 'true size' of some images while others just get scaled to \linewidth? How do you know what to scale them without 'measuring'? – jon Mar 7 '16 at 3:50
• First, a wish to see the command working. Second, it seems more natural to work with scale than. – Xexeo Mar 10 '16 at 0:11

## 1 Answer

You can use an exclamation to reset the width and height values:

\documentclass{article}
\usepackage{graphicx}

\setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio}

\begin{document}
\includegraphics[scale=0.5]{example-image-A}

\includegraphics[width=!,totalheight=!,scale=0.5]{example-image-A}
\end{document}


• If I use \usepackage[french]{babel} in the preamble, and I write something before the second includegraphics, like dfhg \includegraphics[width=!,totalheight=!,scale=0.5]{example-image-A} I got errors. Any ideas why, and what I can do ? – antoine Oct 25 '16 at 10:46
• @antoine french makes the ! active to insert small spaces (when inside a paragraph so you have a problem only if a paragraph has been started). Use either \shorthandoff{!} before the graphic, or width=\detokenize{!}. – Ulrike Fischer Oct 25 '16 at 11:08