在我的源文档中,我有一个图像和一个代码列表,中间由一些文本隔开。当我使用 pdflatex 生成 PDF 时,图像就在列表上方,看起来图像的标题就是列表的标题,即图像的标题离列表比离图像更近。这是我可以重现问题的最短示例。
\documentclass{book}
\usepackage[pdftex]{graphicx}
\usepackage{listings} % code listings
\begin{document}
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
before before before before before before before before before before
\begin{figure}[!htbp]
\centering
\includegraphics[keepaspectratio,width=4cm,clip,trim = 0mm 6cm 15cm 0mm]
{Images/XMLElement}
\caption{Constructor removal in XMLElement}
\label{XMLElement}
\end{figure}
between between between between between between between between
between between between between between between between between
\begin{figure}[!htb]
\lstset{language=Java, showspaces=false,
showstringspaces=false, tabsize=2, breaklines=true}
\begin{lstlisting}[frame=single]
public IXMLElement createElement(String fullName) { }
\end{lstlisting}
\caption{Example2}
\end{figure}
after after after after after after after after after after after
after after after after after after after after after after after
after after after after after after after after after after after
after after after after after after after after after after after
\end{document}
下图显示了上述源代码的输出。在我的完整文档中,第一个标题和代码列表之间的距离更小。如何在第一个标题和第二个图之间插入更多空间(视情况而定)?根据中间的编辑,这两个图可能会或可能不会出现在同一页上。
答案1
您可以根据需要修改长度\floatsep
,它指定页面顶部/底部浮动之间的垂直距离/长度。通过“适当”,您可以排版文档,只需在最后担心这种(手动)微调。
以下最小示例显示了两个重复的页面,除了修改以\floatsep
显示修改浮动分离的效果之外。
\documentclass{article}
\usepackage[demo]{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\lipsum[1]
\begin{figure}[t]
\centering \includegraphics{figure1}
\caption{This is a figure}
\end{figure}
\begin{figure}[t]
\centering \includegraphics{figure2}
\caption{This is another figure}
\end{figure}
\lipsum[2]
\clearpage
\setlength{\floatsep}{1pt}
\lipsum[1]
\begin{figure}[t]
\centering \includegraphics{figure1}
\caption{This is a figure}
\end{figure}
\begin{figure}[t]
\centering \includegraphics{figure2}
\caption{This is another figure}
\end{figure}
\lipsum[2]
\end{document}
来自layouts
包裹 文档可以根据页面/文档浮动元素查看长度(第 21 页及以后):
默认值为 ,12.0pt plus 2.0pt minus 2.0pt
允许2pt
从 进行拉伸12pt
。
也可以skip
使用caption
包裹. 默认为10pt
。