仅当部分未结束时才在页脚中显示内容

仅当部分未结束时才在页脚中显示内容

我正在写一本游戏书。我的文本被分成很多小段落,长度从几行到一页半不等。读者/玩家将从第一段开始,然后根据他们的选择从一个段落移动到另一个段落,通常以以下格式呈现:

If you want to do this, go to paragraph 20.
If you want to do this other thing, go to paragraph 31.
If you want to do this instead, go to paragraph 2.

现在:我注意到,由于这种格式的特殊性,有时不清楚下一页是否还有更多内容可读。例如,在上面的例子中,如果第三行出现在下一页中,玩家将不会意识到它在那里,也不会选择该选项。

我希望通过在页面的右页脚显示一些内容来解决这个问题,以防下一页有更多内容需要阅读。例如“继续阅读...”

我无法拿到文档并实际插入所有这些指示,因为这本书会很大,而且当我导出它们时段落会被随机化(它们实际上会写在另一个由脚本生成的文档中)。此外,每次我修改文本时分页符都会移动,这注定会在游戏最终完成之前发生很多次。

所以:我想我需要使用该包如果那么,并在 RO 和 RE 页脚中放置一个\ifthenelse声明。我的问题是我不知道如何编写条件:我如何询问 LaTeX 该部分是否结束或下一页上还有更多内容?

这是一个 MWE,它生成一个我们可以处理的文档。正如您所看到的,一些部分将在页面末尾结束,其他部分将跨越下一页。在第二种情况下,我需要在页面的页脚中出现“继续阅读...”字样。

\documentclass[a4paper, 11pt]{book}

\usepackage[esperanto]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{microtype}

\pagestyle{fancy}
\fancyhead[LO, RE]{}
\fancyhead[RO]{\small \thepage}
\fancyhead[LE]{\small \thepage}
\fancyhead[CE]{\textit{Profanator}}
\fancyhead[CO]{\textit{Atlante 1}}
\cfoot{}
\renewcommand{\headrulewidth}{0pt}

\begin{document}

\chapter{Example}

\section*{1}
\lipsum[1-2]

\section*{2}
\lipsum[3-4]

\section*{3}
\lipsum[5-6]

\section*{4}
\lipsum[7-8]

\section*{5}
\lipsum[9-10]

\section*{6}
\lipsum[11-12]

\section*{7}
\lipsum[13-14]

\section*{8}
\lipsum[15-16]

\section*{9}
\lipsum[17-18]

\section*{10}
\lipsum[19-20]

\end{document}

编辑 08/07/2023

已要求澄清该问题。可能我没有正确解释我的问题。

目前的情况如下:

在此处输入图片描述

在此处输入图片描述

这是意大利语,但你明白上下文:在分页符处,下一页上还有更多选项这一点并不明显,所以我需要一些东西来表明这一点。我会用文字和符号做一些实验来找到最好的解决方案,但要添加一些东西那里对我来说似乎是正确的起点。这个东西有望解决问题。

Stephen 的解决方案非常完美。我个人不喜欢将 TeX 基元与 LaTeX 命令混合使用,因此我使用该ifthen软件包修改了他的版本。我会将此内容留在这里供未来的用户使用。归根结底,这完全是一回事。

\documentclass[a4paper, 11pt]{book}

\usepackage[esperanto]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{microtype}
\usepackage{refcount}
\usepackage{ifthen}

\pagestyle{fancy}
\fancyhead[LO, RE]{}
\fancyhead[RO]{\small \thepage}
\fancyhead[LE]{\small \thepage}
\fancyhead[C]{}
\fancyfoot[C]{}
\fancyfoot[R]{%
    \ifthenelse{\getpagerefnumber{text-begin-\thetext}<\getpagerefnumber{text-end-\thetext}}%
    {\textit{Keep on reading...}}%
    {}%
}
\fancypagestyle{plain}{}
\renewcommand{\headrulewidth}{0pt}
\newcounter{text}
\newenvironment{text}{%
    \refstepcounter{text}%
    \label{text-begin-\thetext}%
}{%
    \label{text-end-\thetext}%
}

\begin{document}

\chapter{Example}

\section*{1}
\begin{text}\lipsum[1-2]\end{text}

\section*{2}
\begin{text}\lipsum[3-4]\end{text}

\section*{3}
\begin{text}\lipsum[5-6]\end{text}

\section*{4}
\begin{text}\lipsum[7-8]\end{text}

\section*{5}
\begin{text}\lipsum[9-10]\end{text}

\section*{6}
\begin{text}\lipsum[11-12]\end{text}

\section*{7}
\begin{text}\lipsum[13-14]\end{text}

\section*{8}
\begin{text}\lipsum[15-16]\end{text}

\section*{9}
\begin{text}\lipsum[17-18]\end{text}

\section*{10}
\begin{text}\lipsum[19-20]\end{text}

\end{document}

答案1

这个答案基于我在评论中提到的链接。

将每个部分的文本放在一个环境中text,并在环境的两端设置两个标签。

\documentclass[a4paper, 11pt]{book}

\usepackage[esperanto]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{microtype}
\usepackage{refcount}
\pagestyle{fancy}
\fancyhead[LO, RE]{}
\fancyhead[RO]{\small \thepage}
\fancyhead[LE]{\small \thepage}
\fancyhead[CE]{\textit{Profanator}}
\fancyhead[CO]{\textit{Atlante 1}}
\fancyfoot[C]{}
\fancyfoot[R]{%
  \ifnum\getpagerefnumber{text-begin-\thetext}<\getpagerefnumber{text-end-\thetext}%
  \textsl{Keep on reading}%
  \fi}
\fancypagestyle{plain}{}
\renewcommand{\headrulewidth}{0pt}
\newcounter{text}
\newenvironment{text}{\refstepcounter{text}\label{text-begin-\thetext}}%
  {\label{text-end-\thetext}}

\begin{document}

\chapter{Example}

\section*{1}
\begin{text}\lipsum[1-2]\end{text}

\section*{2}
\begin{text}\lipsum[3-4]\end{text}

\section*{3}
\begin{text}\lipsum[5-6]\end{text}

\section*{4}
\begin{text}\lipsum[7-8]\end{text}

\section*{5}
\begin{text}\lipsum[9-10]\end{text}

\section*{6}
\begin{text}\lipsum[11-12]\end{text}

\section*{7}
\begin{text}\lipsum[13-14]\end{text}

\section*{8}
\begin{text}\lipsum[15-16]\end{text}

\section*{9}
\begin{text}\lipsum[17-18]\end{text}

\section*{10}
\begin{text}\lipsum[19-20]\end{text}

\end{document}

在此处输入图片描述

答案2

我不确定是否正确理解了你的问题,但是为什么你不简单地\nopagebreak在每一行的末尾加上你不想独自出现在下一页的内容(即段落的末尾和每一行的末尾都加上“如果你想……去……”)?

\documentclass[a4paper, 11pt]{book}

\usepackage[esperanto]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{microtype}

\pagestyle{fancy}
\fancyhead[LO, RE]{}
\fancyhead[RO]{\small \thepage}
\fancyhead[LE]{\small \thepage}
\fancyhead[CE]{\textit{Profanator}}
\fancyhead[CO]{\textit{Atlante 1}}
\cfoot{}
\renewcommand{\headrulewidth}{0pt}

\begin{document}

\chapter{Example}

\section*{1}
\lipsum[1-2]

Some text just to put the lines on the page border.

Some text just to put the lines on the page border.

Some text just to put the lines on the page border.

Some text just to put the lines on the page border.

Some text just to put the lines on the page border.

Some text just to put the lines on the page border.

Some text just to put the lines on the page border.

Some text just to put the lines on the page border.

Some text just to put the lines on the page border.\nopagebreak

If you want to do this, go to paragraph X.\nopagebreak

If you want to do this other thing, go to paragraph Y.\nopagebreak

If you want to do this instead, go to paragraph Z.\nopagebreak

\section*{2}
\lipsum[3-4]\nopagebreak

If you want to do this, go to paragraph X.\nopagebreak

If you want to do this other thing, go to paragraph Y.\nopagebreak

If you want to do this instead, go to paragraph Z.\nopagebreak

\section*{3}
\lipsum[5-6]\nopagebreak

If you want to do this, go to paragraph X.\nopagebreak

If you want to do this other thing, go to paragraph Y.\nopagebreak

If you want to do this instead, go to paragraph Z.\nopagebreak

\section*{4}
\lipsum[7-8]\nopagebreak

If you want to do this, go to paragraph X.\nopagebreak

If you want to do this other thing, go to paragraph Y.\nopagebreak

If you want to do this instead, go to paragraph Z.\nopagebreak

\section*{5}
\lipsum[9-10]\nopagebreak

If you want to do this, go to paragraph X.\nopagebreak

If you want to do this other thing, go to paragraph Y.\nopagebreak

If you want to do this instead, go to paragraph Z.\nopagebreak

\section*{6}
\lipsum[11-12]\nopagebreak

If you want to do this, go to paragraph X.\nopagebreak

If you want to do this other thing, go to paragraph Y.\nopagebreak

If you want to do this instead, go to paragraph Z.\nopagebreak

\section*{7}
\lipsum[13-14]\nopagebreak

If you want to do this, go to paragraph X.\nopagebreak

If you want to do this other thing, go to paragraph Y.\nopagebreak

If you want to do this instead, go to paragraph Z.\nopagebreak

\section*{8}
\lipsum[15-16]\nopagebreak

If you want to do this, go to paragraph X.\nopagebreak

If you want to do this other thing, go to paragraph Y.\nopagebreak

If you want to do this instead, go to paragraph Z.\nopagebreak

\section*{9}
\lipsum[17-18]\nopagebreak

If you want to do this, go to paragraph X.\nopagebreak

If you want to do this other thing, go to paragraph Y.\nopagebreak

If you want to do this instead, go to paragraph Z.\nopagebreak

\section*{10}
\lipsum[19-20]\nopagebreak

If you want to do this, go to paragraph X.\nopagebreak

If you want to do this other thing, go to paragraph Y.\nopagebreak

If you want to do this instead, go to paragraph Z.\nopagebreak

\end{document}

在此处输入图片描述

答案3

您正在尝试使用 LaTeX 来控制/影响读者的行为。与其更改 LaTeX 代码,不如为读者提供一个视觉提示,让他们知道他们的选项将在下一页继续,就像一个不完整的框一样,这样不是更好吗?您可以使用该framed包来实现这一点:

\documentclass{report}
\usepackage{lipsum}
\usepackage{framed}

\begin{document}


\chapter{The Basics}

\lipsum[5]

\begin{oframed}

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

If you want to do this, go to page X.

\end{oframed} % end minipage

\end{document}

使用带有 oframed 环境的框架包打破盒子

相关内容