是否可以通过测量文本/页面空间来程序化地生成分页符?我遇到了一个问题,您可以在此处看到:
这张图片有两个问题。首先,标题应该溢出到下一页,因为它不适合……但更重要的是,更令人恼火的是,标题应该被强制移到下一页,因为它的内容不适合同一页。
我正在从 javascript 程序生成我的 latex,因此发布代码片段有点困难,但我可以向您展示我正在使用的函数/环境......它是已接受答案中的第二个代码块 这里
对于测量文本有什么想法或技巧吗?
编辑
以下是从上面的链接生成我的自定义列表的代码:
\documentclass{article}
\usepackage{fancyhdr}
\usepackage[head=41.68335pt]{geometry}
\usepackage{enumitem}
\usepackage{indentfirst}
\pagestyle{empty}
%% I use a box for your "title" and save its width in "\mytitlewidth"
\newlength{\mytitlewidth}
\newlength{\mytopsep}
\newsavebox{\mytitlebox}
%% and environment to handle your list
\newenvironment{enumwithinenum}[1]
{\setlength{\mytitlewidth}{\dimexpr0.30\textwidth\relax}%%'
\setlength{\mytopsep}{2ex}%%'
%% save the title in a box so we can access its height later to
%% use to adjust where the next enumerate begins.
\begin{lrbox}{\mytitlebox}%%'
\begin{minipage}[t]{\dimexpr\mytitlewidth\relax}
\raggedright\strut
\textbf{#1}
\par\xdef\tpd{\the\prevdepth}%%'
\end{minipage}%%'
\end{lrbox}%%"
\usebox{\mytitlebox}%%'
\vspace{-\dimexpr\dp\mytitlebox+\parskip+0.7\baselineskip+\mytopsep\relax}%%'
\begin{enumerate}[align=left,
label={.\arabic*},
leftmargin=\dimexpr\mytitlewidth+2em\relax,
topsep=\mytopsep,
]
}
{\end{enumerate}}
%-@-(1)---------------------------------------------------------------------
\begin{document}
\noindent
\textbf{Part One - General}
zzz
\vspace{12.85cm}
\begin{enumerate}[leftmargin=*,topsep=1ex,itemsep=4ex,label={1.\arabic*}]
\item \begin{enumwithinenum}{SECTION INCLUDES}
\item \strut Work covered by Contract documents
\item Contract Method
\item Contract Method
\item Contract Method
\item Contract Method
\item Contract Method
\item Contract Method
\item Contract Method
\item Contract Meth
\end{enumwithinenum}
\item \begin{enumwithinenum}{THIS IS A LONGER TITLE}
\item \strut Work covered by Contract documents
\item Contract Method
\end{enumwithinenum}
\end{enumerate}
\end{document}
答案1
我会将标题与第一项更紧密地绑定在一起:
\documentclass{article}
\usepackage{fancyhdr}
\usepackage[head=41.68335pt]{geometry}
\usepackage{enumitem}
\usepackage{indentfirst}
\pagestyle{empty}
%% I use a box for your "title" and save its width in "\mytitlewidth"
\newlength{\mytitlewidth}
\newlength{\mytopsep}
\newsavebox{\mytitlebox}
%% and environment to handle your list
\newenvironment{enumwithinenum}[1]
{\setlength{\mytitlewidth}{\dimexpr0.30\textwidth\relax}%%'
\setlength{\mytopsep}{2ex}%%'
%% save the title in a box so we can access its height later to
%% use to adjust where the next enumerate begins.
\begin{lrbox}{\mytitlebox}%%'
\begin{minipage}[t]{\dimexpr\mytitlewidth\relax}
\raggedright\strut
\textbf{#1}
\par\xdef\tpd{\the\prevdepth}%%'
\end{minipage}%%'
\end{lrbox}%%"
\begin{enumerate}[align=left,
label={\llap{\smash{\box\mytitlebox}}.\arabic*},
leftmargin=\dimexpr\mytitlewidth+2em\relax,
topsep=\mytopsep,
]
}
{\end{enumerate}}
%-@-(1)---------------------------------------------------------------------
\begin{document}
\noindent
\textbf{Part One - General}
zzz
\vspace{12.85cm}
\begin{enumerate}[leftmargin=*,topsep=1ex,itemsep=4ex,label={1.\arabic*}]
\item \begin{enumwithinenum}{SECTION INCLUDES}
\item \strut Work covered by Contract documents
\item Contract Method
\item Contract Method
\item Contract Method
\item Contract Method
\item Contract Method
\item Contract Method
\item Contract Method
\item Contract Meth
\end{enumwithinenum}
\item \begin{enumwithinenum}{THIS IS A LONGER TITLE}
\item \strut Work covered by Contract documents
\item Contract Method
\end{enumwithinenum}
\end{enumerate}
\end{document}