これまでドキュメントで外部画像を使用したことはありませんでしたが、今日は何か調べる必要がありました。偶然見つけたのgraphicx
ですが、この制約に合うように、すべての画像を縮小して(必要な場合)、たとえば 300 ピクセルの幅を超えないようにするにはどうしたらよいか疑問に思っています。
あなたの助けに感謝します。
答え1
内の幅をチェックする自動化\hbox
:
\documentclass{article}
\usepackage{graphicx}
\newsavebox{\mybox}
\let\oldincludegraphics\includegraphics
\xdef\maxwidth{0.9\textwidth}
\renewcommand{\includegraphics}[2][]{%
\savebox{\mybox}{%
\hbox{\oldincludegraphics[#1]{#2}}}%
\ifdim\wd\mybox>\maxwidth
\oldincludegraphics[width=\maxwidth,keepaspectratio]{#2}%
\else
\oldincludegraphics[#1]{#2}%
\fi}
\begin{document}
\includegraphics{image1.png}
\includegraphics[width=0.3\textwidth]{image2.png}
\includegraphics[width=1.4\textwidth]{image3.png}
\end{document}
PS: 推奨されるかどうかはわかりませんが、画像 1、2、3 のサイズと幅を変えて試してみて確認してください。