我想在文档的最后一页打印一些图形(包含一些致谢等)。我不知道最终文档的长度,因为它是模板,因此我需要一个更通用的解决方案,而不是手动摆弄htbp
限定符\clearpage
等。这是我的 MWE:
\documentclass{article}
\usepackage[a6paper,margin=0.5cm,landscape]{geometry}
\usepackage{graphicx}
\usepackage{blindtext}
\pagestyle{empty}
\begin{document}
\raggedbottom
\blindtext\footnote{A footnote.}
% uncomment to move float to the next page
%\blindtext
\begin{figure}[bp!]
\includegraphics[draft,width=\linewidth,height=2cm]{documentfooter.pdf}
\end{figure}
\end{document}
如果最后一页的文本过多,浮动内容会移至第二页。但现在浮动内容在该页上垂直居中,而不是在底部对齐。
此外,脚注应排版在致谢部分上方。理想情况下,直接附在上面的文本上,而不是致谢部分。事实上,文档的所有内容(例如其他图表、表格等)都必须位于致谢开始之前。
致谢部分不必包含在图中。但这是我能想到的唯一方法。请注意,页码等的位置不应受到解决方案的影响。
答案1
这会将图像添加为最后一页页脚的一部分:
\documentclass{article}
\usepackage[a6paper,margin=0.5cm,landscape]{geometry}
\usepackage{graphicx}
\usepackage{blindtext}
\pagestyle{empty}
\AtEndDocument{\enlargethispage{-2.5cm}\thispagestyle{credits}}
\makeatletter
\def\ps@credits{%
\def\@oddfoot{\hfill
\smash{\includegraphics[draft,width=\linewidth,height=2cm]{documentfooter.pdf}}%
\hfill}}
\makeatother
\begin{document}
\raggedbottom
\blindtext\footnote{A footnote.}
% uncomment to move float to the next page
%\blindtext
\end{document}
我 (Steven Segletes) 觉得根据 David 的回答做出独立解决方案不太合适,所以我选择编辑他的回答 (David,如果觉得不好,可以随时回滚)。我采纳了 David 的回答,并将命令添加\vfill
到他的宏的开头\AtEndDocument
。它处理了讨论的几个用例,包括 David 的原始解决方案不足的用例。
\documentclass{article}
\usepackage[a6paper,margin=0.5cm,landscape]{geometry}
\usepackage{graphicx}
\usepackage{blindtext}
\pagestyle{empty}
\AtEndDocument{\vfill\enlargethispage{-2.5cm}\thispagestyle{credits}}
\makeatletter
\def\ps@credits{%
\def\@oddfoot{\hfill
\smash{\includegraphics[draft,width=\linewidth,height=2cm]{documentfooter.pdf}}%
\hfill}}
\makeatother
\begin{document}
\raggedbottom
\blindtext\footnote{A footnote.}
% uncomment to move float to the next page
\blindtext
\end{document}
答案2
以下(有点复杂的方法)似乎涵盖了所有情况:
\documentclass{article}
% packages needed only for the purpose of illustration
\usepackage[a6paper,margin=0.5cm,bottom=1.5cm,landscape]{geometry}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{blindtext}
% packages which are actually used for putting the credits box at the right place
\usepackage{calc}
\usepackage{scrextend}
\usepackage[absolute]{textpos}
\usepackage{needspace}
\usepackage{etoolbox}
% patch the \Needspace command: not only end the current page in case of
% insufficient space but always create an empty new one
\makeatletter
\patchcmd{\@needsp@}{\break}{\break\null}{\typeout{good}}{\typeout{bad}}
\makeatother
\AtEndDocument{%
% put the credits into a box
\newsavebox{\credits}%
\sbox{\credits}{\includegraphics[draft,width=\linewidth,height=2cm]{documentfooter.pdf}}%
%
% measure its total height
\newlength{\creditstotalheight}%
\settototalheight{\creditstotalheight}{\usebox{\credits}}%
%
% check if there is enough space on the current page
% otherwise insert a page break
\Needspace{\creditstotalheight}%
%
% reduce the size of the current page by the total height of the credits box
% this is needed since \Needspace doesn't recognize footnotes
% (they would overlay with the credits box)
\enlargethispage{-\creditstotalheight}%
%
% calculate the upper left corner of the credits block
% within the text area
\newlength{\creditsx}%
\newlength{\creditsy}%
\ifthispageodd{%
\setlength{\creditsx}{\dimexpr 1in+\hoffset+\oddsidemargin \relax}%
}{%
\setlength{\creditsx}{\dimexpr 1in+\hoffset+\evensidemargin \relax}%
}%
\setlength{\creditsy}{\dimexpr 1in+\voffset+\topmargin+\headsep+\headheight
+\textheight-\creditstotalheight \relax}%
%
% typeset the credits at the computed position
\begin{textblock*}{\widthof{\usebox{\credits}}}(\creditsx,\creditsy)%
\noindent\usebox{\credits}%
\end{textblock*}%
\pagebreak% issue a page break to bring the \raggedbottom into effect on this page
}
\begin{document}
\pagebreak
\thispagestyle{plain}
\raggedbottom
\blindtext\footnote{A footnote.}
% uncomment to get a two page output
%\blindtext[2]
\end{document}
结果如果text+credits < 1 page
:
结果如果text+credits > 1 page
: