附件

附件

我想确保随意的文档的一部分始终打印在同一页面上。

注1:

我的问题集中在列表和表格上。但是,我相信解决方案(如果有的话)是通用的,并不只适用于这两个元素。

笔记2:

我提供了(简单的)代码来说明我在 GitHub 帐户上尝试执行的操作(在此处放置代码会使帖子难以阅读)。请查看此链接

注3:

这个问题看起来与链接后面的问题相同,但事实并非如此:绝对,绝对,防止分页

上述链接所给出的问题的答案适用于“整个元素”列表。我的意思是:例如,整个段落、整个项目列表或整个表格。例如,您可以确保段落和表格(即:2 个“整个元素”)打印在同一页上。

但是你能确保“整个元素”和“另一个元素的某些部分”打印在同一页面上吗?

例如:我想确保标题(即一个段落 - “整个元素”)以及至少前两行下表(元素的某些部分)将打印在同一页上吗?

我尝试使用下面显示的宏(如前面提到的响应所建议的那样)。

% See https://tex.stackexchange.com/questions/94699/absolutely-definitely-preventing-page-break
\newenvironment{absolutelynopagebreak}{
  \par\nobreak\vfil\penalty0\vfilneg
  \vtop\bgroup
}{\par\xdef\tpd{\the\prevdepth}\egroup\prevdepth=\tpd}

我也尝试使用“minipage”容器(也如前面提到的回应所建议的那样)。

我找到了一种仅适用于列表的解决方法。您无需声明一个长列表,而是将列表分成几个较小的部分。这不是一个完全令人满意的解决方法,因为在另一个上下文中它可能无法很好地工作。请参阅这个例子结果

但是,这种解决方法不适用于列宽不固定的表格。由于列的宽度不固定,因此同一列可能具有不同的宽度,具体取决于表格的部分。这个例子结果

这个根本问题似乎与 LaTeX 代码本身的语法有关:“begin/end”语句必须平衡。因此,您不能干扰“整个元素”(完整表格的完整列表)的结构。您不得不将其拆分成更小的部分。

任何想法 ?

谢谢。

附件

列表.tex

\documentclass{class}

% See http://borntocode.fr/latex-customisation-de-listes-a-puces/
\newenvironment{packed_enum}{
   \begin{itemize}[topsep=0pt, itemsep=1pt, parsep=0pt, partopsep=0pt]%
}{\end{itemize}}

% See https://tex.stackexchange.com/questions/94699/absolutely-definitely-preventing-page-break
\newenvironment{absolutelynopagebreak}{
  \par\nobreak\vfil\penalty0\vfilneg
  \vtop\bgroup
}{\par\xdef\tpd{\the\prevdepth}\egroup\prevdepth=\tpd}


\begin{document}

   % Nothing prevents the title to be printed on one page and the 10 items on
   % the next page. I would like to make sure that the title and, at least 2
   % items, will be printed on the same page.

   Title
   \vspace{15pt}

   \begin{packed_enum}
      \item Iten 1
      \item Iten 2
      \item Iten 3
      \item Iten 4
      \item Iten 5
      \item Iten 6
      \item Iten 7
      \item Iten 8
      \item Iten 9
      \item Iten 10
      \item Iten 11
      \item Iten 12
      \item Iten 13
      \item Iten 14
      \item Iten 15
      \item Iten 16
      \item Iten 17
      \item Iten 18
   \end{packed_enum}
   \vspace{5cm}

   % One solution, that works for the list.
   % But, please note: I create 2 lists instead of one.

   \begin{absolutelynopagebreak}
      Title
      \vspace{15pt}

      \begin{packed_enum}         % <= first list
         \item Iten 1
         \item Iten 2
      \end{packed_enum}
   \end{absolutelynopagebreak}
   \begin{packed_enum}            % <= second list
      \item Iten 3
      \item Iten 4
      \item Iten 5
      \item Iten 6
      \item Iten 7
      \item Iten 8
      \item Iten 9
      \item Iten 10
      \item Iten 11
      \item Iten 12
      \item Iten 13
      \item Iten 14
      \item Iten 15
      \item Iten 16
      \item Iten 17
      \item Iten 18
   \end{packed_enum}

\end{document}

表格.tex

\documentclass{class}

% ---------------------------------------------------------------------------
% I define fiew environments.
% ---------------------------------------------------------------------------

% See https://www.sharelatex.com/learn/Tables
\newenvironment{packed_tabular}{
   \setlength{\tabcolsep}{0pt}
}

% See https://tex.stackexchange.com/questions/94699/absolutely-definitely-preventing-page-break
\newenvironment{absolutelynopagebreak}{
  \par\nobreak\vfil\penalty0\vfilneg
  \vtop\bgroup
}{\par\xdef\tpd{\the\prevdepth}\egroup\prevdepth=\tpd}

\begin{document}

   % 1. Nothing prevents the title to be printed on one page and the 5 lines of
   %    the table to be printed on the next page. I would like to make sure that
   %    the title and, at least 2 lines, will be printed on the same page.
   % 2. The table cannot be broken. All rows are printed the one after the other...
   %    even if the end of the text area is reached.

   Title
   \vspace{15pt}

   \begin{packed_tabular}
      \begin{tabular}{lcl}
          a   & ~ & experience 0 \\
          aa  & ~ & experience 1 \\
          aaa & ~ & experience 2 \\
          a   & ~ & experience 3 \\
          aa  & ~ & experience 4 \\
          aaa & ~ & experience 5 \\
          a   & ~ & experience 6 \\
          aa  & ~ & experience 7 \\
          aaa & ~ & experience 8 \\
          a   & ~ & experience 9 \\
          aa  & ~ & experience 10 \\
          aaa & ~ & experience 11 \\
          a   & ~ & experience 12 \\
          aa  & ~ & experience 13 \\
          aaa & ~ & experience 14 \\
          a   & ~ & experience 15 \\
          aa  & ~ & experience 16 \\
          aaa & ~ & experience 17 \\
         \end{tabular}%
   \end{packed_tabular}%

   % One solution may be to split the table into smaller tables.
   % But this solution does not work **well**.
   % The widths of the columns are not fixed.
   % Therefore the tables may have different widths for the same columns.

   \begin{absolutelynopagebreak}
      Title
      \vspace{15pt}

      \begin{packed_tabular}
         \begin{tabular}{|l|c|l|}
             a   & ~ & experience 0 \\
             aa  & ~ & experience 1 \\
             aaa & ~ & experience 2 \\
             a   & ~ & experience 3 \\
         \end{tabular}%
      \end{packed_tabular}%
   \end{absolutelynopagebreak}%
%
   \begin{absolutelynopagebreak}
      \begin{packed_tabular}%
         \begin{tabular}{|l|c|l|}%
             a & ~ & experience 4 \\
             a & ~ & experience 5 \\
         \end{tabular}%
      \end{packed_tabular}%
   \end{absolutelynopagebreak}%
%
   \begin{absolutelynopagebreak}%
      \begin{packed_tabular}%
         \begin{tabular}{|l|c|l|}%
             a & ~ & experience 6 \\
             a & ~ & experience 7 \\
             a & ~ & experience 8 \\
             a & ~ & experience 9 \\
             a & ~ & experience 10 \\
             a & ~ & experience 11 \\
             a & ~ & experience 12 \\
             a & ~ & experience 13 \\
             a & ~ & experience 14 \\
             a & ~ & experience 15 \\
             a & ~ & experience 16 \\
             a & ~ & experience 17 \\
         \end{tabular}%
      \end{packed_tabular}%
   \end{absolutelynopagebreak}%

\end{document}

类.cls

% This file contains LaTeX configuration for all CV.

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{class}[1995/10/30 Standard LaTeX minimal class]

% This class "article" defines many important things.
% See https://tex.stackexchange.com/questions/440462/hline-does-not-produce-anything/440468#440468
\LoadClass{article}

% [geometry] This package provides a flexible and easy interface to page dimensions.
\usepackage[a4paper,
            % We set the dimensions of the left and right margins.
            left=1cm,
            right=1cm,
            % We set the dimensions of the top and bottom margins.
            top=12cm,
            bottom=12cm]{geometry}

% We (must) redefine the font size named "normalsize" (this is mandatory).
% Please note that LaTeX defines other names for font sizes (for example: tiny, small...).
% See https://www.sharelatex.com/learn/Font_sizes,_families,_and_styles#Reference_guide
% WARNING: Make sure to redefine the command "\normalsize" before loading the package "fontspec".
\renewcommand{\normalsize}{\fontsize{10pt}{12pt}\selectfont}

% This package allows the use of formatting features that are required to draw tables.
\usepackage{array}

% This package provides flexibility for fine-tuning the enumerated lists.
% See https://texfaq.org/FAQ-complist
\usepackage{enumitem}

% This package is really awasome.
\usepackage{tcolorbox}

% This will print a frame around the text area.
\usepackage{showframe}

Makefile

# This document illustrates the use of the "make" tool to produce PDF files from LaTeX sources.
# 
#      Generate the PDF file:                              make all
#      Clean all the temporary files:                      make clean
#      Remove all temporary files, including the PDF file: make clear


LATEX_EXE     = /usr/bin/lualatex
LATEX_OPTIONS = -halt-on-error -shell-escape -interaction=nonstopmode --output-format=pdf
PDF_VIEWER    = xdg-open 

list.pdf: list.tex class.cls
    ${LATEX_EXE} ${LATEX_OPTIONS} $< && echo "SUCCESS" && ${PDF_VIEWER} $@

table.pdf: table.tex class.cls
    ${LATEX_EXE} ${LATEX_OPTIONS} $< && echo "SUCCESS" && ${PDF_VIEWER} $@

all: list.pdf table.pdf

clean:
    rm -f *.log *.out *.aux

clear: clean
rm -f *.pdf

相关内容