在此回答,有一个宏可以让人精确控制文档的页面长度。
这个宏对我来说太复杂了,我发现它有一个问题。它在itemize
环境中表现得很奇怪。我正在寻求帮助来改进这个宏,以便它能正常地运行itemize
。
宏的目标
宏的目标是根据具有以下约束的源生成PDF
文档:LaTeX
- 页面的默认高度是一个参数
defaultLength
- 还有另一个参数:
initialVerticalInset
- 第一页的高度应该是
defaultLength - initialVerticalInset
- 最后一页的高度等于“其内容的高度”,即“最后一页位于”其内容结束后
- 所有其他页面的高度都等于
defaultLength
实验后添加的其他约束:
- 如果将任何页面放在另一页面旁边,则基线应该对齐
- 如果可能的话,宏应该兼容
mdframed
宏
这是宏:
[...]
\flushbottom
\setlength{\maxdepth}{0pt}% to address the "third bug"
\setlength{\topskip}{0pt}% no space above the first line
% assuming the page number is the absolute page number
\usepackage{zref-totpages,zref-savepos}
\usepackage{atbegshi}
\makeatletter
\providecommand*{\zsaveposy}{\zsavepos}% for older zref-savepos
\def\@oddhead{\PosFirstHead\PosLastHead\hss}%
\def\@evenhead{\PosLastHead\hss}%
\newcommand*{\PosFirstHead}{%
\ifnum\value{page}=1 %
\zsaveposy{PosFirstHead}%
\global\let\PosFirstHead\@empty
\fi
}
\newcommand*{\PosLastHead}{%
\ifnum\value{page}=\ztotpages
\zsaveposy{PosLastHead}%
\global\let\PosLastHead\@empty
\fi
}
\AtBeginShipout{%
\ifnum\value{page}=1 %
\dimen@=\dimexpr
\zposy{PosFirstHead}sp-\headsep
-\zposy{PosFirst}sp%
\relax
\setbox\AtBeginShipoutBox=\vbox{%
\kern-\dimen@ %
\copy\AtBeginShipoutBox
}%
\advance\pdfpageheight by -\dimen@
\else
\ifnum\value{page}=\ztotpages
\advance\pdfpageheight by%
-\dimexpr
\textheight
-\zposy{PosLastHead}sp+\headsep
+\zposy{PosLast}sp%
\relax
\fi
\fi
}
\AtEndDocument{%
\par
\nobreak
\dimen@=\prevdepth
\ifdim\dimen@>\maxdepth
\kern-\maxdepth
\else
\ifdim\dimen@>0pt %
\kern-\dimen@
\fi
\fi
\zsaveposy{PosLast}%
}
\makeatother
\usepackage{lipsum}% provides dummy text
\interlinepenalty=-100
\begin{document}
\vspace*{\dimexpr5cm-\topskip plus 1fill}% first page should not be larger than 15cm
\zsaveposy{PosFirst}
\nointerlineskip
[...]
失败的 MWE
这是显示该问题的 MWE。第一页应该有正常高度。但是,它比较短。
\documentclass{article}
\usepackage%
[paperwidth=10.000000cm,
paperheight=8cm,
hmargin=1.000000mm,
top=1.000000mm,
bottom=1.000000mm]
{geometry}
\pagestyle{empty}
\flushbottom
\setlength{\maxdepth}{0pt}% to address the "third bug"
\setlength{\topskip}{0pt}% no space above the first line
% assuming the page number is the absolute page number
\usepackage{zref-totpages,zref-savepos}
\usepackage{atbegshi}
\makeatletter
\providecommand*{\zsaveposy}{\zsavepos}% for older zref-savepos
\def\@oddhead{\PosFirstHead\PosLastHead\hss}%
\def\@evenhead{\PosLastHead\hss}%
\newcommand*{\PosFirstHead}{%
\ifnum\value{page}=1 %
\zsaveposy{PosFirstHead}%
\global\let\PosFirstHead\@empty
\fi
}
\newcommand*{\PosLastHead}{%
\ifnum\value{page}=\ztotpages
\zsaveposy{PosLastHead}%
\global\let\PosLastHead\@empty
\fi
}
\AtBeginShipout{%
\ifnum\value{page}=1 %
\dimen@=\dimexpr
\zposy{PosFirstHead}sp-\headsep
-\zposy{PosFirst}sp%
\relax
\setbox\AtBeginShipoutBox=\vbox{%
\kern-\dimen@ %
\copy\AtBeginShipoutBox
}%
\advance\pdfpageheight by -\dimen@
\else
\ifnum\value{page}=\ztotpages
\advance\pdfpageheight by%
-\dimexpr
\textheight
-\zposy{PosLastHead}sp+\headsep
+\zposy{PosLast}sp%
\relax
\fi
\fi
}
\AtEndDocument{%
\par
\nobreak
\dimen@=\prevdepth
\ifdim\dimen@>\maxdepth
\kern-\maxdepth
\else
\ifdim\dimen@>0pt %
\kern-\dimen@
\fi
\fi
\zsaveposy{PosLast}%
}
\makeatother
\usepackage{lipsum}% provides dummy text
\interlinepenalty=-100
\begin{document}
\vspace*{\dimexpr0.000cm-\topskip plus 1fill}
\zsaveposy{PosFirst}
\nointerlineskip
This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it?
This is a test:
\begin{itemize}
\item Hello
\item This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test.
\item Good Bye
\item Hello
\item This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test.
\end{itemize}
This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it?
This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it?
This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it? This is a test. This is a longer sentence with some more words, isn't it?
\end{document}
答案1
线条
%\setlength{\maxdepth}{0pt}% to address the "third bug"
%\setlength{\topskip}{0pt}% no space above the first line
%\vspace*{\dimexpr0.000cm-\topskip plus 1fill}
永远无法对文档做任何有用的事情,如果我删除它们,第一页就是预期的大小。