适合浮动页面

适合浮动页面

这是处理不同图像尺寸时最佳图形尺寸调整。我想调整图形的大小,使包括标题在内的图形适合页面。前面提到的问题已经解释了如何仅调整图形的大小。解决方案如下:

\documentclass[a4paper,10pt]{scrartcl}  
\usepackage{graphicx}  
\begin{document}  
\begin{figure}  
\centering  
\includegraphics[width=\textwidth,height=\textheight]{AnyGraphic}  
\caption{Some random caption. This should be long enough to create at least one line break, as the overall size of the float naturally depends on the size of the caption}  
\end{figure}  
\end{document}

没有标题,一切都很好。但包含标题会导致警告Float too large for page
因此问题是:如何将包含标题的浮动元素放入页面?
注意:我想对具有不同长度标题的许多浮动元素执行此操作。因此,我更喜欢适用于任意长度标题的解决方案。

答案1

如果你同时使用两者widthheight那么你也几乎总是想使用,keepaspectratio否则图像将被扭曲以匹配指定的尺寸。对于其余的,你可以这样做:

\documentclass[a4paper,10pt]{scrartcl}  
\usepackage{graphicx}  
\begin{document}  
\begin{figure}  
\centering  

\includegraphics[width=\textwidth,height=\dimexpr\textheight-4\baselineskip-\abovecaptionskip-\belowcaptionskip\relax,
keepaspectratio]{ug}  
\caption{Some random caption. This should be long enough to create at least one linebreak, as the overall size of the float naturally depends on the size of the caption}  
\end{figure}  
\end{document}

或者你可以测量标题。我会收到一个警告,说浮动太大了 0.04385pt,这看起来很像深度,但我并不担心,而是减去一个额外的值2pt以求好运。keepaspectratio被注释掉,这样我的测试图像就会在这个方向上拉伸。

\documentclass[a4paper,10pt]{scrartcl}  
\usepackage{graphicx} 
\newsavebox\cpsave 
\begin{document}  
\begin{figure}  
\centering  
\savebox\cpsave{\begin{minipage}{\textwidth}\vspace*{\abovecaptionskip}%
\caption{Some random caption. This sholud be long enough to create at least one linebreak, as the overall size of the float naturally depends on the size of the caption}\end{minipage}}

\includegraphics[width=\textwidth,height=\dimexpr\textheight-\ht\cpsave-\dp\cpsave-\lineskip-2pt\relax,
%keepaspectratio
]{ug}  

\noindent\usebox\cpsave
\end{figure}  
\end{document}

相关内容