0

(For background and current purpose of this question, please see here: Prevent page break within \item of an enumerate).

I have an enumerate of questions. Each of those questions has some opening text and then a nested enumerate. I give an example below that results in a page-break in the middle of the second question in the PDF output. I mark with \newpage where I would like the page-break to be (automatically) inserted. In this particular example, I want the first question to be on page 1, and the second and third to be on page 2 (just because they both happen to fit).

There are some answers at Prevent page break within \item of an enumerate, but I would like a LyX-specific solution, and I do not want to redefine \item because \item is used besides just the enumerate environment. I would like something that works on the LyX layout level so that I can either use it as a module, or local layout, without changing any of the contents of the body.

Here is a LyX minimal example:

#LyX 2.3 created this file. For more info see http://www.lyx.org/
\lyxformat 544
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\begin_preamble

%% my attempt: %\let\OldItem\item %\renewcommand{\item}{\OldItem \ifnum @listdepth=1 \begin{samepage}\fi} %\AfterEndEnvironment{enumerate}{\ifnum @listdepth=1 \end{samepage}\fi} \end_preamble \use_default_options false \maintain_unincluded_children false \language english \language_package none \inputencoding auto \fontencoding default \font_roman "default" "default" \font_sans "default" "default" \font_typewriter "default" "default" \font_math "auto" "auto" \font_default_family default \use_non_tex_fonts false \font_sc false \font_osf false \font_sf_scale 100 100 \font_tt_scale 100 100 \use_microtype false \use_dash_ligatures true \graphics default \default_output_format default \output_sync 0 \bibtex_command default \index_command default \paperfontsize default \spacing single \use_hyperref false \papersize default \use_geometry false \use_package amsmath 1 \use_package amssymb 0 \use_package cancel 0 \use_package esint 1 \use_package mathdots 0 \use_package mathtools 0 \use_package mhchem 0 \use_package stackrel 0 \use_package stmaryrd 0 \use_package undertilde 0 \cite_engine basic \cite_engine_type default \biblio_style plain \use_bibtopic false \use_indices false \paperorientation portrait \suppress_date false \justification true \use_refstyle 0 \use_minted 0 \index Index \shortcut idx \color #008000 \end_index \secnumdepth 3 \tocdepth 3 \paragraph_separation indent \paragraph_indentation default \is_math_indent 0 \math_numbering_side default \quotes_style english \dynamic_quotes 0 \papercolumns 1 \papersides 1 \paperpagestyle default \tracking_changes false \output_changes false \html_math_output 0 \html_css_as_file 0 \html_be_strict false \end_header

\begin_body

\begin_layout Enumerate 2 + 2 = ? \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \end_layout

\begin_deeper \begin_layout Enumerate 1 \end_layout

\begin_layout Enumerate 2 \end_layout

\begin_layout Enumerate 3 \end_layout

\begin_layout Enumerate 4 \end_layout

\begin_layout Standard \begin_inset ERT status collapsed

\begin_layout Plain Layout

% I do not want to put this page break in manually: \end_layout

\begin_layout Plain Layout

\end_layout

\end_inset

\begin_inset ERT status collapsed

\begin_layout Plain Layout

% \backslash newpage \end_layout

\begin_layout Plain Layout

\end_layout

\end_inset

\end_layout

\end_deeper \begin_layout Enumerate Consider the joint probability distribution below: filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \end_layout

\begin_deeper \begin_layout Standard \align center \begin_inset Tabular <lyxtabular version="3" rows="3" columns="3"> <features tabularvalignment="middle"> <column alignment="center" valignment="top"> <column alignment="center" valignment="top"> <column alignment="center" valignment="top"> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset </cell> <cell alignment="center" valignment="top" topline="true" usebox="none"> \begin_inset Text

\begin_layout Plain Layout \begin_inset Formula $X_{2}=0$ \end_inset

\end_layout

\end_inset </cell> <cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none"> \begin_inset Text

\begin_layout Plain Layout \begin_inset Formula $X_{2}=1$ \end_inset

\end_layout

\end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none"> \begin_inset Text

\begin_layout Plain Layout \begin_inset Formula $X_{1}=0$ \end_inset

\end_layout

\end_inset </cell> <cell alignment="center" valignment="top" topline="true" usebox="none"> \begin_inset Text

\begin_layout Plain Layout \begin_inset Formula $\frac{1}{10}$ \end_inset

\end_layout

\end_inset </cell> <cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none"> \begin_inset Text

\begin_layout Plain Layout \begin_inset Formula $\frac{3}{10}$ \end_inset

\end_layout

\end_inset </cell> </row> <row> <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none"> \begin_inset Text

\begin_layout Plain Layout \begin_inset Formula $X_{1}=1$ \end_inset

\end_layout

\end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" usebox="none"> \begin_inset Text

\begin_layout Plain Layout \begin_inset Formula $\frac{2}{10}$ \end_inset

\end_layout

\end_inset </cell> <cell alignment="center" valignment="top" topline="true" bottomline="true" rightline="true" usebox="none"> \begin_inset Text

\begin_layout Plain Layout \begin_inset Formula $\frac{4}{10}$ \end_inset

\end_layout

\end_inset </cell> </row> </lyxtabular>

\end_inset

\end_layout

\begin_layout Standard What is \begin_inset Formula $P(X_{1}=1)$ \end_inset

? \end_layout

\begin_layout Enumerate I do not know.

\end_layout

\begin_layout Enumerate 4 \end_layout

\begin_layout Enumerate 17 \end_layout

\begin_layout Enumerate 88 \end_layout

\end_deeper \begin_layout Enumerate 2 - 2 + 5 = filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \begin_inset Newline newline \end_inset

filler \end_layout

\begin_deeper \begin_layout Enumerate 1 \end_layout

\begin_layout Enumerate 2 \end_layout

\begin_layout Enumerate 3 \end_layout

\begin_layout Enumerate 4 \end_layout

\end_deeper \end_body \end_document

scottkosty
  • 13,164

0 Answers0