I am working with environments to be able to easily format the content of a document.
Now I want to define a rule so that the content from the ccetheme
environment appears on the same page as the content from the next environment: it can be ccebody
or ccesection
I have seen that it can be done with needspace
or minipage
, but I can't do it.
This is my minimal example:
\documentclass[ebook,11pt,twoside,openright,showtrims]{memoir}
\setstocksize{9in}{6in}
\settrimmedsize{9in}{6in}{*}
\setbinding{0.5in}
\setlrmarginsandblock{0.5in}{0.4in}{*}
\setulmarginsandblock{0.5in}{0.5in}{*}
\setheadfoot{12.07pt}{\footskip}
\checkandfixthelayout
\usepackage{fontspec}
\newfontfamily\headerfont{Libertinus Sans}
\usepackage{polyglossia}
\setdefaultlanguage{spanish}
\usepackage{csquotes}
\usepackage{xcolor}
\usepackage{layout}
\usepackage{needspace}
\usepackage{lipsum}
\usepackage[showframe, pass]{geometry}
\newcommand{\txtred}{\textcolor{red}}
\newcommand\n[1]{\txtred{\textbf{#1}}}
%--------------------------------------------------------------------- CCE styles
\newenvironment{ccetheme}[1]{%
% \begin{cr}{#1}
\nopagebreak
\par% Start a new paragraph
\addvspace{\baselineskip}% Space above
\centering% Alignment
\bfseries% Weight
\color{red}% Colour
{\large #1\par}% Change to \LARGE or \Huge
\ignorespaces
}
{% \end{cr}
\par% Start a new paragraph
\addvspace{\baselineskip}% Space below
%\begin{minipage}[t]{0.5\textwidth}
%\end{minipage}
}
%Títulos en negrita del propio CCE
\newenvironment{ccesection}{%
% \begin{cr}{#1}
\par% Start a new paragraph
\addvspace{\baselineskip}% Space above
\bfseries% Weight
\ignorespaces
}
{% \end{cr}
\par% Start a new paragraph
\addvspace{\baselineskip}% Space below
}
\newenvironment{ccebody}{%
\begin{minipage}{0.5\linewidth}
%\textit{redtext}\
%\fontfamily{gentium}\selectfont
\end{minipage}
}%
{% \end{cr}
%\nopagebreak
%\par% Start a new paragraph
%\addvspace{\baselineskip}% Space below
}
\newenvironment{ccecite}{%
% \begin{cr}{#1}
\par% Start a new paragraph
\addvspace{\baselineskip}% Space above
\alterfont% Font
\ignorespaces
\leftskip1cm\relax
\rightskip1cm\relax
}
{% \end{cr}
\par% Start a new paragraph
\addvspace{\baselineskip}% Space below
}
\begin{document}
\section{Temas}
\begin{ccetheme}{La Alianza con Noé} {CEC 56-58, 71}\end{ccetheme}
\begin{ccebody}
\n{56} \lipsum[1-3]
\end{ccebody}
\begin{ccetheme}{Test} {CEC NNNN}\end{ccetheme}
\begin{ccebody}
\n{57} \lipsum[1-3]
\end{ccebody}
\begin{ccebody}
\n{58} \lipsum[5]
\end{ccebody}
\begin{ccebody}
\n{59} \lipsum[6-8]
\end{ccebody}
\begin{ccetheme}{Test} {CEC MMMM}\end{ccetheme}
\begin{ccebody}
\begin{ccesection}This is title on bold\end{ccesection}
\n{59} \lipsum[1-3]
\end{ccebody}
\begin{ccebody}
\n{60} \lipsum[5]
\end{ccebody}
\end{document}
As you can see in the images below, in this particular case there is an unpleasant cut between the ccetheme
environment and the ccebody
environment.
Also in this case, where I use the ccesection environment I would like the content of ccetheme along with the following to go to the next page:
I want to know if there is any way to force ccetheme
content to always appear on the same page as the next paragraph.
As you can see, to achieve this I am putting \nopagebreak
in ccetheme
environment and trying to implement minipage
in ccebody
, but it doesn't work.
\nopagebreak
after the\par
inccetheme
probably does somethingccebody
paragraphs stick together on the same page it would work as I hope. Is there a way to indicate that in the ccebody environment? Sorry for not giving a complete example, the text is too long.