我想知道如何在 Lyx 中定义前导码,以便在图形太宽或太高时调整宽度和高度。我已经尝试过这个:
\usepackage{graphicx}
% Determine if the image is too wide for the page.
\makeatletter
\def\ScaleIfNeeded{%
\ifdim\Gin@nat@width>\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}
\makeatother
% Resize figures that are too wide for the page.
\let\oldincludegraphics\includegraphics
\renewcommand\includegraphics[2][]{%
\oldincludegraphics[width=\ScaleIfNeeded]{#2}
}
然而,问题是太高的图像仍然太高,我怎样才能在序言中调整宽度和高度?
答案1
您可以在 LaTeX 序言中添加以下内容:
\usepackage[export]{adjustbox}% http://ctan.org/pkg/adjustbox
% Resize figures that are too wide for the page.
\let\oldincludegraphics\includegraphics
\renewcommand\includegraphics[2][]{%
\oldincludegraphics[#1,max width=\linewidth,max height=\textheight]{#2}
}
adjustbox
允许设置maximum width
或maximum height
包含的图像并对其进行相应的修改。
请注意,如果将 设置为maximum height
,\textheight
则包含在浮点数中的图像和标题可能不太合适。您可能需要考虑小于 的内容\textheight
。