具有分頁符號的同時靈活的垂直空間

具有分頁符號的同時靈活的垂直空間

遇到一個我無法弄清楚的問題。本質上,我有一個頁面,其中包含一些文本,可能是一些方程式,一些圖形,可能還有一個表格,所有這些都由靈活的空白分隔。有時所有內容都適合一頁,但有時圖形太大,因此需要多頁。

假設我有 3 個圖形。如果它們都太大而無法放在一頁上,我希望前兩個圖形保留在第一頁上,與任何前面的文本均勻分佈,第三個圖形將與下一頁一起出現以下文本或表格等。

我的印像是,這是由於\vspace創建了一個牢不可破的vbox,但我不知道如何在不手動添加 a\clearpage或類似的情況下處理我想要的東西。這是不受歡迎的;當然,最終目標是幾乎可以自動為我完成此操作的模板!

這是一個 MWE。在此範例中,影像 A 和 B 最終出現在第 2 頁。

\documentclass[letterpaper,10pt,article,oneside,openany]{memoir}
\usepackage[T1]{fontenc}
\usepackage[margin=0.8in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{mwe}

\begin{document}

\mainmatter

\section{A section}

\subsection{the first subsection}

Some text here

\vfill

\begin{center}
\textbf{Some title text} \\*
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-a}

\vfill

\textbf{More title text} \\*
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-b}

\vfill

\textbf{Even more title text} \\*
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-c}
\end{center}

\subsection{The next subsection}

\end{document}

結果: 結果

我所期望的 MSPaint 粗略再現: 在此輸入影像描述

答案1

問題

MWE 中發生的情況是,無限可拉伸的跳過與 引入的負(分頁符號)懲罰之間的相互作用導致centerTeX 的分頁演算法得出結論,沒有比環境內容之前更好的分頁位置center了。這就是為什麼使用\centering而不是center環境會有所幫助。然而,類似的問題仍然會出現在章節標題和清單環境周圍。

在環境的開頭插入負懲罰(用於分頁),center因為它內部使用 atrivlist並且列表的開頭被認為是分頁的好地方。這種負懲罰鼓勵 TeX 在此時破壞頁面(如果它已經是一個可以這樣做的地方),我的意思是這樣做不會導致任何膠水拉伸得太遠。然而,因為您已經插入了一些無限可拉伸的膠水,所以拉伸量不會太多,這會得出這樣的結論:在環境開始時結束頁面比center頁面已滿時結束頁面更好。由於無限拉伸,在那裡放置分頁符號沒有任何成本,但它的好處(在 TeX 看來)是分頁符號發生在自然的位置。

分頁演算法的詳細描述可以在第27.4節找到TeX 按主題

除了強制分頁之外,我思考負懲罰(預設)僅插入以下位置:

  • 以上各節標題,
  • 圍繞著列表環境(包括center例如定理環境,因為它們是使用實現的\trivlist),
  • 之間\item
  • 透過一堆明確執行此操作的使用者命令(\pagebreak[n]\smallbreak等),
  • 其他? (如果我錯過了什麼,請告訴我)

解決方案/解決方法

為了避免因負懲罰而提前發生分頁符,您可以將這些負懲罰設為零。若要對章節標題和清單內/周圍執行此操作,請將以下行新增至序言:

\makeatletter       %% <- make @ usable in command sequences
\@secpenalty=0      %% <- don't encourage breaks before section heading
\@beginparpenalty=0 %% <- don't encourage breaks at start of list environments
\@endparpenalty=0   %% <- don't encourage breaks at end of list environments
\@itempenalty=0     %% <- don't encourage breaks between items
\makeatother        %% <- revert @

當然,這樣做的一個副作用是,在這些地方將不再鼓勵分頁。 (他們仍會灰心喪氣,例如然而,章節標題。

我已經定義了一個環境版本figure,我認為它或多或少可以滿足您的需求(前提是上述所有懲罰都設為零)。無法移動到上一頁/下一頁的無限可拉伸將插入到其周圍。您可以類似地shamtamtable為表定義一個環境。

\newcommand*\topvfill{%
  \par                      %% <- switch to vertical mode
  \penalty 0                %% <- allow a page break here, but don't encourage it
  \vspace*{0pt plus 1fill}% %% <- unremovable infinitely stretchable space
}
\newcommand*\bottomvfill{%
  \par                      %% <- switch to vertical mode
  \vspace{0pt plus 1fill}%  %% <- infinitely stretchable space
  \penalty 0                %% <- allow a page break here
}

\usepackage{float} % <- for the [H] option
\newenvironment{shamtamfig}{%
  \topvfill    %% <- insert flexible space above
  \figure[H]%  %% <- begin inner figure environment
  \centering   %% <- horizontally centre content
}{%
  \endfigure   %% <- end figure environment
  \bottomvfill %% <- insert flexible space below
}

您的 MWE 會發生這些變化

這是您的 MWE,\vfill替換為\beakablevfill並將上述負懲罰設為零。我添加了顯示文字區域邊框的showframe選項geometry,並且做了一些細微的更改以使此演示更加清晰。

\documentclass[letterpaper,10pt,article,oneside,openany]{memoir}
\usepackage[margin=0.8in, showframe]{geometry} %% <- added showframe for demonstration
\usepackage{graphicx}

\makeatletter %% <- make @ usable in command sequences
\@beginparpenalty=0 % <- start of list env
\@endparpenalty=0   % <- end of list env
\@itempenalty=0     % <- between items
\@secpenalty=0      % <- before section heading
\makeatother  %% <- revert @

\newcommand*\topvfill{%
  \par                      %% <- switch to vertical mode
  \penalty 0                %% <- allow a page break here, but don't encourage it
  \vspace*{0pt plus 1fill}% %% <- unremovable infinitely stretchable space
}
\newcommand*\bottomvfill{%
  \par                      %% <- switch to vertical mode
  \vspace{0pt plus 1fill}%  %% <- infinitely stretchable space
  \penalty 0                %% <- allow a page break here
}
\def\midvfill{%
  \par                       %% <- switch to vertical mode
  \vspace{0pt plus 1fill}%   %% <- infinitely stretchable space
  \penalty 0                 %% <- allow a page break here, but don't encourage it
  \vspace{0pt plus -1fill}%  %% <- cancels out the previous \vspace if no page break occurred
  \vspace*{0pt plus 1fill}%  %% <- unbreakable/unremovable infinitely stretchable space
}

\usepackage{float} % <- for the [H] option

\newenvironment{shamtamfig}{%
  \topvfill    %% <- insert flexible space above
  \figure[H]%  %% <- begin inner figure environment
  \centering   %% <- horizontally centre content
}{%
  \endfigure   %% <- end figure environment
  \bottomvfill %% <- insert flexible space below
}

\usepackage{blindtext} % <- for demonstration purposes

\begin{document}

\section{A section}

\subsection{the first subsection}

\blindtext[2]

\blindtext

\begin{shamtamfig}
    \textbf{Some title text}\par
    \includegraphics[width=0.6\textwidth]{example-image-a}
\end{shamtamfig}

\begin{shamtamfig}
    \textbf{More title text}\par
    \includegraphics[width=0.4\textwidth]{example-image-b}
\end{shamtamfig}

\begin{shamtamfig}
    \textbf{Even more title text}\par
    \includegraphics[width=0.4\textwidth]{example-image-c}
\end{shamtamfig}

\subsection{The next subsection}

\blindtext

\blinditemize

\blindtext[2]

\begin{shamtamfig}
    \textbf{Even more title text}\par
    \includegraphics[width=0.6\textwidth]{example-image}
\end{shamtamfig}

\end{document}

為了好玩,您可以嘗試註解掉\@...penalty=0此範例中的幾行,看看這些行有什麼效果。

第一頁 第二頁 第三頁

答案2

在此輸入影像描述

\documentclass[letterpaper,10pt,article,oneside,openany]{memoir}

\usepackage[T1]{fontenc}
\usepackage[margin=0.8in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{mwe}

\begin{document}

%\pagestyle{fancy}

\mainmatter

\section{A section}

\subsection{the first subsection}

Some text here

\vfill

{\centering
\textbf{Some title text} \\*
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-a}


\vfill

\textbf{More title text} \\*
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-b}

\vfill

\textbf{Even more title text} \\*
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-c}

}

\subsection{The next subsection}

\end{document}

您會稍微幸運一些,\centering但實際上問題在於使用\\*而不是正確的切片或\item命令。在\centering(and center)的範圍內,\\實際上\par而不是其通常的定義,\newline這意味著它會執行分頁符,\\*增加\nobreak懲罰,因此,如果發生在標題之後考慮分頁符的情況,則會在此處阻止分頁符,因為*但是由於\vfill可以填充空間,因此在第一個圖像之前可以使用零罰分符,因此 TeX 會採用該分頁符號而不是向前查看。


\\避免使用顯式間距字體更改並支持更慣用的乳膠標記的可能更好的標記\caption

在此輸入影像描述

\documentclass[letterpaper,10pt,article,oneside,openany]{memoir}

\usepackage[T1]{fontenc}
\usepackage[margin=0.8in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{mwe,float}

\begin{document}

%\pagestyle{fancy}

\mainmatter

\section{A section}

\subsection{the first subsection}

Some text here

\begin{figure}[H]
  \centering
\caption{Some title text}
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-a}  
\end{figure}

\begin{figure}[H]
  \centering
\caption{Some title text}
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-b}  
\end{figure}

\begin{figure}[H]
  \centering
\caption{Some title text}
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-c}  
\end{figure}



\subsection{The next subsection}

\end{document}

您可以使用 float (和相關)的功能caption來根據需要自訂標題格式。

答案3

我不確定您的意思是“靈活的空白”,但您可以定義一個\vspace與預先定義的“靈活長度”一起使用的新命令。

\documentclass[letterpaper,10pt,article,oneside,openany]{memoir}
\usepackage[T1]{fontenc}
\usepackage[margin=0.8in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{mwe}

\newlength{\mylength}
\setlength{\mylength}{20pt plus 10pt minus 5pt}
\newcommand{\myskip}{\vspace{\mylength}}
\begin{document}

\mainmatter

\section{A section}

\subsection{the first subsection}

Some text here

\myskip

\begin{center}
\textbf{Some title text} \\*
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-a}

\myskip

\textbf{More title text} \\*
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-b}

\myskip

\textbf{Even more title text} \\*
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-c}
\end{center}

\subsection{The next subsection}

\end{document}

PS:不確定我是否理解了這個問題,所以請隨時要求我刪除它。

答案4

如果您想使用,center最好將每個區塊放入自己的環境中。

\documentclass[letterpaper,10pt,article,oneside,openany]{memoir}
\usepackage[T1]{fontenc}
\usepackage[margin=0.8in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{mwe}

\begin{document}    
\mainmatter    
\section{A section}    
\subsection{the first subsection}    
Some text here    
\vfill    
\begin{center}
\textbf{Some title text} \\*
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-a}
\end{center}    
\vfill    
\begin{center}
\textbf{More title text} \\*
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-b}
\end{center}    
\vfill    
\begin{center}
\textbf{Even more title text} \\*
\includegraphics[width=0.75\textwidth,keepaspectratio]{example-image-c}
\end{center}    
\subsection{The next subsection}    

\end{document}

相關內容