如果页面不适合,请避免使用文本

如果页面不适合,请避免使用文本

前段时间,我发了一个问题,如果由于页面限制而导致段落中断,是否强制创建新页面。这个问题通过一个完美的答案解决了。但是,除了将文本拆分到新页面中,是否可以完全忽略它?这意味着,如果段落不适合,是否可以跳过整个段落?

这是当前的代码(抱歉,定义有些奇怪)

\newcommand{\uComment}[3]{%
  \filbreak
  \begin{commentTextFont}#1\end{commentTextFont}%
  \vspace*{0.5cm}
  \begin{userFont}\textit{#2}\hspace*{\fill}%
  \begin{dateFont}#3\end{dateFont}\end{userFont}%
  \vspace*{0.8cm}
}


%------------------------
% Invoke Packages
%------------------------

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{lipsum,lineno}

%------------------------
% Set Dimensions
%------------------------
\usepackage[ 
  paperwidth = 168.3mm,
  paperheight = 260.4mm,
  top = 6mm,
  bottom = 7mm,
  outer = 6mm,
  inner = 20mm
]{geometry}

%------------------------
% Remove indentation from all paragraphs
%------------------------
\setlength\parindent{0pt}

% Comments
\newcommand{\CommentFontSize}{21}
\newcommand{\CommentSkipMult}{25}
% Author
\newcommand{\UserFontSize}{16}
\newcommand{\UserSkipMult}{0}
% Date
\newcommand{\DateFontSize}{15}
\newcommand{\DateSkipMult}{0}

% Comments
\newenvironment{commentTextFont}
 {\fontfamily{mdugm}%
  \fontsize{\CommentFontSize}{\CommentSkipMult}%
  \selectfont}
 {\par}
% Author
\newenvironment{userFont}
 {\fontfamily{mdugm}%
  \fontsize{\UserFontSize}{\UserSkipMult}%
  \selectfont}
 {\par}
% Date
\newenvironment{dateFont}
 {\fontfamily{mdugm}%
  \fontsize{\DateFontSize}{\DateSkipMult}%
  \selectfont}
 {\par}

%------------------------
% Set commands 
%------------------------

\newcommand{\uComment}[3]{%
  \filbreak
  \begin{commentTextFont}#1\end{commentTextFont}%
  \vspace*{0.5cm}
  \begin{userFont}\textit{#2}\hspace*{\fill}%
  \begin{dateFont}#3\end{dateFont}\end{userFont}%
  \vspace*{0.8cm}
}

%------------------------
% Document
%------------------------

\begin{document}

\raggedright

\uComment{\lipsum[73]}{someone}{2000}
\uComment{\lipsum[75]}{someone}{2000}
\uComment{\lipsum[66]}{someone}{2000}

\end{document}

答案1

\printifspace好吧,这里有一个想法。我省略了您的字体自定义等,只解决了删除跨两页的段落的问题。如果剩余空间足够,参数将进入当前页面;否则,它将被删除。

\documentclass{article}

\usepackage{lipsum,lmodern,calc,ifthen,pgffor}

% determine how much space is left on the current page
\newcommand*\measurepage{\dimexpr\pagegoal-\pagetotal\relax}

\newsavebox{\mybox}
\newlength{\boxheight}

% put content in a savebox to determine if it fits onto the page. 
% if it does, typeset it; if not, ignore it and move on to next page.
\newcommand{\printifspace}[1]{%
    \sbox{\mybox}{\parbox{\textwidth}{#1\par\medskip\par}}%
    \setlength{\boxheight}{\ht\mybox+\dp\mybox}%
    \ifthenelse{\boxheight<\measurepage}%
        {\usebox{\mybox}\par}%
        {\typeout{dropped an overflowing chunk}\clearpage}%
}

\begin{document}

\foreach \x in {1,2,...,20}{\printifspace{\x: \lipsum[\x]}}

\end{document}

使用边距和字体大小的默认设置(至少在我的系统上),第 5、第 11 和第 17 段将被删除。

相关内容