# Resize all images in Latex to a percentage width

I am auto-generating multiple tex files using pandoc (one tex file for each of my chapters). Pandoc generates this tex code for each image.

\begin{figure}[htbp]
\centering
\includegraphics{images/flock_of_birds.JPG}
\caption{A flock of storks rush to fill orders during the Baby Boom.}
\end{figure}


How can I set the width of all images to a percentage value without directly modifying the generated code? I have attempted to use \renewcommand\includegraphics but my LaTex knowledge falls short.

-

## migrated from stackoverflow.comOct 30 '12 at 14:25

This question came from our site for professional and enthusiast programmers.

Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  Werner Oct 31 '12 at 6:21

You can redefine the existing \includegraphics macro to apply any options you desire.


## Notes:

• Normally one could use the \let\OldIncludegraphics{\includegraphics} syntax, but since \includegraphics has an optional parameter we need to use LetLtxMacro from the letltxmacro package A detailed description of \LetLtxMacro can be found at this question about a closed square root symbol.

• The [demo] option is used so as to place a black box where the figure would go for demo purposes, in your real usage (when you actually have the figures available), you need to remove this option.

## Code:

\documentclass{article}
\usepackage[demo]{graphicx}% Remove [demo] option in real usage.
\usepackage{letltxmacro}

\LetLtxMacro{\OldIncludegraphics}{\includegraphics}

\begin{document}
\begin{figure}[htbp]
\centering
\includegraphics{images/flock_of_birds.JPG}
\caption{A flock of storks rush to fill orders during the Baby Boom.}
\end{figure}

\renewcommand{\includegraphics}[2][]{\OldIncludegraphics[width=9cm, #1]{#2}}

\begin{figure}[htbp]
\centering
\includegraphics{images/flock_of_birds.JPG}
\caption{A flock of storks rush to fill orders during the Baby Boom.}
\end{figure}

\end{document}

-
Actually \includegraphics does not require \LetLtxMacro, but using it doesn't hurt. :) –  egreg Oct 30 '12 at 21:06
\documentclass{article}

scales every image down to 20%. You can also define width=0.3\linewidth or something else.