我正在使用环境来轻松地格式化文档的内容。
现在我想定义一条规则,以便来自该环境的内容ccetheme
与来自下一个环境的内容出现在同一个页面上:它可以是ccebody
或ccesection
我已经看到可以用needspace
或来完成minipage
,但我做不到。
这是我的最小例子:
\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}
正如您在下面的图片中看到的,在这种特殊情况下,ccetheme
环境与ccebody
环境之间存在令人不快的切割。
同样在这种情况下,当我使用 ccesection 环境时,我希望 ccetheme 的内容以及以下内容转到下一页:
我想知道是否有任何方法可以强制ccetheme
内容始终与下一段出现在同一页面上。
正如您所看到的,为了实现这一点,我投入了\nopagebreak
环境ccetheme
并尝试minipage
在其中实现ccebody
,但没有成功。
答案1
这仍然有一些警告,间距可以调整,但我认为像这样的东西更接近你想要的
当您需要包围大块文本时,如果括号参数和环境的数量固定,也可以使用命令。
\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
\newcommand{\ccetheme}[2]{%
\def\cceA{#1}%
\def\cceB{#2}%
}
%Títulos en negrita del propio CCE
\newcommand{\ccesection}[1]{%
\par% Start a new paragraph
\addvspace{\baselineskip}% Space above
\noindent\textbf{#1}%
\par
}
\newenvironment{ccebody}{%
\par% Start a new paragraph
\noindent\begin{minipage}[t]{\linewidth}%
\setlength\parindent{15pt}%
\ifx\cceA\relax\else
\begin{center}
\bfseries% Weight
\color{red}% Colour
\large \cceA\\\cceB
\end{center}%
\fi
\global\let\cceA\relax
\par
}%
{\end{minipage}%
\par}
\newenvironment{ccecite}{%
% \begin{cr}{#1}
\quote
\alterfont% Font
}
{\endquote
}
\raggedbottom
\begin{document}
\section{Temas}
\ccetheme{La Alianza con Noé} {CEC 56-58, 71}
\begin{ccebody}
\n{56} \lipsum[1-3]
\end{ccebody}
\ccetheme{Test} {CEC NNNN}
\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}
\ccetheme{Test} {CEC MMMM}
\begin{ccebody}
\ccesection{This is title on bold}
\n{59} \lipsum[1-3]
\end{ccebody}
\begin{ccebody}
\n{60} \lipsum[5]
\end{ccebody}
\end{document}