3

To set the default scaling values for the \includegraphics command, one can use \setkeys{Gin}{(key)=value)} from the graphicx package. For example, say I put down

\setkeys{Gin}{width=.7\textwidth}

This will automatically scale all succeeding \includegraphics commands by the above width value. Is there a way to turn off this setting for certain graphics? That is, is there a way to still use \includegraphics without having the width set as the above?

I'm aware that

\begin{group}
\setkeys{Gin}{width=.7\textwidth}
\includegraphics{pizza.jpg} %this uses setted values
\end{group}
\includegraphics{pizza.jpg} %this uses normal values

works, but I'm wondering if I can do this without having to surround the \setkeys{Gin} command.

  • \includegraphics[width=2cm]{pizza.jpg} (or the length you want) should override the default value. Never use \begin{group} and \end{group}. – egreg Mar 15 '13 at 23:06
  • What I mean is that I want to \includegraphics{pizza.jpg} in its native setting, i.e., with absolutely no scaling values in place. Something like [width=2cm] only overwrites the scaling value with another one. – Dustin Tran Mar 15 '13 at 23:09
1

You can use the value stored in \Gin@nat@width, defining a handier interface to it:

\documentclass{article}
\usepackage{graphicx}

\setkeys{Gin}{width=30pt} % exaggerated for the example
\makeatletter
\let\ginnatwidth\Gin@nat@width
\makeatother

\begin{document}
\includegraphics{example-image-9x16}

\includegraphics[width=\ginnatwidth]{example-image-9x16}
\end{document}

enter image description here

  • 1
    Sorry, late response! Yes, this works perfectly. By extension, one can do the same for height as well. :) – Dustin Tran Mar 18 '13 at 4:17
  • umm, this doesn't actually turn it off, but sets it do a default value. What I mean is that includegraphics resizes width when only height is given. I have a global default width=\linewidth, but for a particular figure with many images, I want to have a default height and forget about the default width. Using \Gin@nat@width doesn't let includegraphics to adapt width to newer height – Ciprian Tomoiagă Mar 13 '18 at 14:59

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.