Me encuentro con un problema que no puedo resolver. En esencia, tengo una página que tiene algo de texto, posiblemente algunas ecuaciones, un par de gráficos y tal vez una tabla, todo separado por espacios en blanco flexibles. A veces todo cabe en una página, pero a veces los gráficos son demasiado grandes por lo que se necesitan varias páginas.
Digamos que tengo 3 gráficos. En el caso de que sean demasiado grandes para caber en una página, esperaría que los dos primeros gráficos permanezcan en la primera página, distribuidos uniformemente junto con el texto anterior, y el tercer gráfico estaría en la página siguiente junto con el siguiente texto o tablas, etc. Sin embargo, mi código siempre mantiene los tres gráficos juntos.
Tengo la impresión de que se debe a \vspace
la creación de un irrompible vbox
, pero no sé de qué otra manera manejar lo que quiero sin agregar manualmente uno \clearpage
o similar. Esto es indeseable; El objetivo final son plantillas que hagan esto de forma prácticamente automática por mí, ¡por supuesto!
Aquí hay un MWE. En este ejemplo, las imágenes A y B terminan en la página 2. Mi deseo es que la imagen A termine en la página 1, y B, C y la siguiente sección en la página 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}
Respuesta1
El problema
Lo que está sucediendo en su MWE es que la interacción entre los saltos infinitamente extensibles y la penalización negativa (salto de página) introducida por center
está provocando que el algoritmo de salto de página de TeX concluya que no hay mejor lugar para un salto de página que justo antes del contenido del center
entorno. . Por eso ayuda el uso \centering
en lugar del center
medio ambiente. Sin embargo, seguirán surgiendo problemas similares en torno a los títulos de las secciones y los entornos de las listas.
Se inserta una penalización negativa (por salto de página) al inicio del center
entorno porque internamente utiliza un trivlist
y el inicio de una lista se considera un buen lugar para un salto de página. Esta penalización negativa anima a TeX a romper la página en este punto si ya era un lugar adecuado para hacerlo, con lo que quiero decir que hacerlo no provocaría que el pegamento se estirara demasiado. Sin embargo, debido a que ha insertado un poco de pegamento infinitamente estirable, ninguna cantidad de estiramiento es demasiado, lo que lleva a la conclusión de que center
es preferible finalizar la página al comienzo del entorno que hacerlo cuando la página está llena. No hay ningún costo asociado con colocar un salto de página allí debido al estiramiento infinito, pero tiene el beneficio (en la mente de TeX) de que el salto ocurre en un lugar natural para ello.
Una descripción detallada del algoritmo de salto de página se puede encontrar en la sección 27.4 deTeX por tema.
Aparte de los saltos de página forzados,pensarpenalizaciones negativas que (por defecto) sólo se insertan en los siguientes lugares:
- títulos de las secciones anteriores,
- alrededor de entornos de lista (que incluyen
center
, por ejemplo, entornos de teoremas, ya que se implementan mediante\trivlist
), - entre
\item
s, - por un montón de comandos de usuario que hacen esto explícitamente (
\pagebreak[n]
,\smallbreak
, etc.), - ¿otro? (Alguien por favor avíseme si me perdí algo)
Una solución / solución alternativa
Para evitar que se produzcan saltos de página antes de lo necesario debido a penalizaciones negativas, puede establecer estas penalizaciones negativas en cero. Para hacer esto para los encabezados de sección y las listas dentro/alrededor, agregue las siguientes líneas a su preámbulo:
\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 @
Un efecto secundario de hacer esto es, por supuesto, que ya no se fomentarán los saltos de página en estos lugares. (Seguirán desanimados, por ejemplodespuésencabezados de sección, sin embargo.) Esto tampoco le ayudará si cualquier otro tipo de entorno/comando inserta penalizaciones negativas, así que tenga cuidado con eso.
He definido una versión del figure
entorno que creo que hace más o menos lo que quieres (siempre que todas las penalizaciones anteriores estén establecidas en cero). A su alrededor se insertará una extensión infinitamente extensible que no puede pasar a la página anterior/siguiente. De manera similar, podría definir un shamtamtable
entorno para tablas.
\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
}
Tu MWE con estos cambios
Aquí está su MWE \vfill
reemplazado por \beakablevfill
y con las penalizaciones negativas antes mencionadas establecidas en cero. Agregué la showframe
opción para geometry
mostrar el borde del área de texto y realicé algunos cambios menores para que esta demostración sea más clara.
\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}
Por diversión, puedes intentar comentar algunas de las \@...penalty=0
líneas de este ejemplo para ver qué efecto tienen.
Respuesta2
\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}
Tienes un poco más de suerte, \centering
pero en realidad el problema es usar \\*
la sección o los comandos adecuados en lugar de hacerlo \item
. En el alcance de \centering
(y center
), \\
en realidad, \par
en lugar de su definición habitual, \newline
eso significa que ejerce el salto de página, \\*
agrega una \nobreak
penalización, por lo que si sucede que se considera un salto de página después del encabezado, se evita un salto allí debido a *
pero un El salto de penalización cero está disponible antes de la primera imagen debido a que \vfill
está disponible para llenar el espacio, por lo que TeX toma ese salto de página en lugar de mirar hacia adelante.
Un marcado quizás mejor evitando el uso de cambios de fuente de espaciado explícito y \\
a favor del \caption
marcado de látex más idiomático sería
\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}
Puede utilizar las funciones del flotante (y los relacionados caption
) para personalizar el formato de los subtítulos según sea necesario.
Respuesta3
No estoy seguro de lo que quiere decir con "espacio en blanco flexible", pero podría definir un nuevo comando que se usaría \vspace
con una "longitud flexible" predefinida.
\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}
PD: No estoy seguro de haber entendido la pregunta, así que no dudes en pedirme que la elimine.
Respuesta4
Si desea utilizarlo center
, es mejor colocar cada bloque en su propio entorno.
\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}