0

I am trying to make a recipe book. I want to have a pagebreak before each new recipe except it can fit on the remaining space of the page.

I first try to include my recipe in minipage, but recipes longer than a page are displayed on one page (and or cutted).

The I try Needspace package which does not seem to be what I want, because I do not want to loose space if a short recipe can fit in the remaining space of the page.

Here is a non-working example : I would like section2 on a new page.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[a6paper]{geometry}
\usepackage[french]{babel}
\usepackage{lipsum}
\linespread{1.5} 
\newenvironment{env1}{\vspace{-1em}\begin{flushright} \itshape }{\end{flushright}\vspace{-1em}}
\title{Test2}

\begin{document}

\section*{section 1}
\begin{env1}
env1 text
\end{env1}
\lipsum[1][1-4]
\section*{section 2}
\begin{env1}
env1 text
\end{env1}
\begin{enumerate}
    \item item1
    \item item2
    \item item3
\end{enumerate}
\lipsum[1][1-4]
\section*{section 3}
\begin{env1}
env1 text
\end{env1}
\lipsum[1][1-4]
\begin{enumerate}
    \item item1
    \item item2
    \item item3
    \item item4
    \item item5
    \item item6
\end{enumerate}
\section*{section 4}
\begin{env1}
env1 text
\end{env1}
\lipsum[1][1-3]
\end{document}

EDIT

@David Calisle : Thanks for help. Perhaps I misuse needspace : if I would like section 2 on new page (because it does not fit on the remaining space) I need to use \needspace{.7\textheight} (0.6 is not enough). But now Section4 is sent to a new page while it could fit below the section3 (on the same page).

Here is an overleaf link of the code below : https://www.overleaf.com/read/mdstfpxpwwsp

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{needspace}
\usepackage[a6paper]{geometry}
\usepackage[french]{babel}
\usepackage{lipsum}
\usepackage{titlesec}
\linespread{1.5} 
\let\LaTeXStandardSection\section
\makeatletter
\renewcommand{\section}[1]{\needspace{0.7\textheight}\LaTeXStandardSection{#1} }
\makeatother
\newenvironment{env1}{\vspace{-1em}\begin{flushright} \itshape }{\end{flushright}\vspace{-1em}}
\title{Test2}

\begin{document}

\section{section 1}
\begin{env1}
env1 text
\end{env1}
\lipsum[1][1-2]
\section{section 2}
\begin{env1}
env1 text
\end{env1}
\begin{enumerate}
    \item item1
    \item item2
    \item item3
\end{enumerate}
\lipsum[1][1-4]
\section{section 3}
\begin{env1}
env1 text
\end{env1}
\lipsum[1][1-2]
\begin{enumerate}
    \item item1
    \item item2
\end{enumerate}
\section{section 4}
\begin{env1}
env1 text
\end{env1}
\lipsum[1][1-2]
\end{document}
3
  • 1
    Welcome! What you describe is pretty much the behavior of floats.
    – user194703
    Apr 26, 2020 at 7:14
  • needspace should do what you need. if it doesn't give an example that fails that we can debug Apr 26, 2020 at 7:36
  • 1
    This is a duplicate of 535641/dynamic-page-break-before-section. (Why are tcolorbox and minipage keywords?) In summary, put \filbreak before each \section. Apr 26, 2020 at 8:09

1 Answer 1

1

Donals Arseneau give me the answer I need. But I cannot choose this answer as it is a comments. By adding \filbreak before all sections, the behaviour of pagebreak is what I need.

\let\LaTeXStandardSubsection\subsection
\makeatletter
\renewcommand{\subsection}[1]{\filbreak\LaTeXStandardSubsection{#1}}
\makeatother

Thank you all for your help.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .