我尝试使用renewcommand
do redefine includegraphics,如下所示在这个答案中:
% save the meaning of \includegraphics
\LetLtxMacro\latexincludegraphics\includegraphics
\renewcommand{\includegraphics}[2][]{\includegraphics[width=5cm]{#2}}
对于这个最小测试用例:
\documentclass{beamer}
% save the meaning of \includegraphics
\LetLtxMacro\latexincludegraphics\includegraphics
\renewcommand{\includegraphics}[2][]{\includegraphics[width=0.25\textwidth]{#2}}
\begin{document}
\begin{frame}
\includegraphics{test.png}
\end{frame}
\end{document}
其中包括这个数字:
我收到此错误:
! TeX capacity exceeded, sorry [input stack size=5000].
<to be read again>
\def
l.12 \end{frame}
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on main.log.
如何使用renewcommand
来includegraphics
固定图形宽度?
答案1
最好使用以下方法全局设置密钥\setkeys
:
\setkeys{Gin}{width=0.25\textwidth}
答案2
或者,您也可以使用\newcommand
, 代替\renewcommand
。事实上,我甚至建议您首先这样做,因为这样\includegraphics
可以保留原始命令。
答案3
我为常用的图像尺寸(整页、整行、半页等)定义了几个图形宏。
您可以通过创建自定义长度来进一步定制它\newlength{\TallFigureHeight} \setlength{\TallFigureHeight}{\textheight}
,然后将其用作这些命令中的参数。
\newcommand{\insertWideFigure}[1]{%
\includegraphics[width=\linewidth]{#1}%
}
\newcommand{\insertTallFigure}[1]{%
\includegraphics[height=\textheight]{#1}%
}
用法:
\insertWideFigure{images/picture}