我正在使用练习包在很长的文档中编写练习。文档中多次出现练习标题(下面 MWE 中的练习 0.1)出现在页面底部。我可以使用它将\newpage
标题移动到下一页,但我可能想在以后的某些练习之前添加更多文本,所以这不是一个好选择。
我可以添加一些代码来确保练习标题不会单独出现在页面底部吗?
我尝试在发生这种情况的地方创建一个 MWE。
\documentclass[12pt,twoside]{article}
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\usepackage[usenames,svgnames,dvipsnames,table]{xcolor}
\colorlet{lightcyan}{cyan!40!white}
\setlength{\parskip}{1em}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{tasks}
\settasks{label-format={\bfseries}, column-sep={10pt}}
\usepackage[lastexercise,answerdelayed]{exercise}
\counterwithin{Exercise}{section}
\counterwithin{Answer}{section}
\renewcounter{Exercise}[section]
\newcommand{\QuestionNB}{\fbox{\bfseries\arabic{Question}}\ }
\renewcommand{\ExerciseName}{\textbf{Exercise}}
\renewcommand{\ExerciseHeader}{\noindent\def\stackalignment{l}% code from https://tex.stackexchange.com/a/195118/101651
\stackunder[0pt]{\colorbox{cyan}{\textcolor{white}{\LARGE\ExerciseName\;\textbf{\LARGE\ExerciseHeaderNB}}}}{\textcolor{lightcyan}{\rule{\linewidth}{2pt}}}\medskip}
\setlength{\QuestionIndent}{16pt}
\begin{document}
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
ABC
\begin{Exercise}
\Question Solve the following equations, giving exact answers.
\begin{tasks}(2)
\task $\dfrac{5}{x}=2$
\task $\dfrac{5x+6}{3}+\dfrac{4-x}{5}=3$
\end{tasks}
\Question Solve, giving your answers correct to 3 significant figures.
\begin{tasks}(2)
\task $\dfrac{x(x+1)^2}{3(x-1)}=x^2$
\task $\dfrac{2}{x+3}-\dfrac{1}{x-7}=1$
\end{tasks}
\end{Exercise}
\end{document}
答案1
这是一个需要空间的解决方案。
\documentclass[12pt,twoside]{article}
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\usepackage[usenames,svgnames,dvipsnames,table]{xcolor}
\colorlet{lightcyan}{cyan!40!white}
\setlength{\parskip}{1em}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{tasks}
\settasks{label-format={\bfseries}, column-sep={10pt}}
\usepackage[lastexercise,answerdelayed]{exercise}
\counterwithin{Exercise}{section}
\counterwithin{Answer}{section}
\renewcounter{Exercise}[section]
\newcommand{\QuestionNB}{\fbox{\bfseries\arabic{Question}}\ }
\renewcommand{\ExerciseName}{\textbf{Exercise}}
\renewcommand{\ExerciseHeader}{\noindent\def\stackalignment{l}% code from https://tex.stackexchange.com/a/195118/101651
\stackunder[0pt]{\colorbox{cyan}{\textcolor{white}{\LARGE\ExerciseName\;\textbf{\LARGE\ExerciseHeaderNB}}}}{\textcolor{lightcyan}{\rule{\linewidth}{2pt}}}\medskip}
\setlength{\QuestionIndent}{16pt}
\usepackage{stackengine}
\usepackage{needspace}
\begin{document}
\noindent\rule{\textwidth}{32\baselineskip}% 31\baselineskip will include part of the exercise
\needspace{2\baselineskip}% could be bigger
\begin{Exercise}
\Question Solve the following equations, giving exact answers.
\begin{tasks}(2)
\task $\dfrac{5}{x}=2$
\task $\dfrac{5x+6}{3}+\dfrac{4-x}{5}=3$
\end{tasks}
\Question Solve, giving your answers correct to 3 significant figures.
\begin{tasks}(2)
\task $\dfrac{x(x+1)^2}{3(x-1)}=x^2$
\task $\dfrac{2}{x+3}-\dfrac{1}{x-7}=1$
\end{tasks}
\end{Exercise}
\end{document}
此版本仅允许大于的练习0.5\textheight
分页。
我最初使用\box
而不是\unvbox
牢不可破的版本,但这导致页面顶部的间距出现问题。
\documentclass[12pt,twoside]{article}
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\usepackage[usenames,svgnames,dvipsnames,table]{xcolor}
\colorlet{lightcyan}{cyan!40!white}
\setlength{\parskip}{1em}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{tasks}
\settasks{label-format={\bfseries}, column-sep={10pt}}
\usepackage[lastexercise,answerdelayed]{exercise}
\counterwithin{Exercise}{section}
\counterwithin{Answer}{section}
\renewcounter{Exercise}[section]
\newcommand{\QuestionNB}{\fbox{\bfseries\arabic{Question}}\ }
\renewcommand{\ExerciseName}{\textbf{Exercise}}
\renewcommand{\ExerciseHeader}{\noindent\def\stackalignment{l}% code from https://tex.stackexchange.com/a/195118/101651
\stackunder[0pt]{\colorbox{cyan}{\textcolor{white}{\LARGE\ExerciseName\;\textbf{\LARGE\ExerciseHeaderNB}}}}{\textcolor{lightcyan}{\rule{\linewidth}{2pt}}}\medskip}
\setlength{\QuestionIndent}{16pt}
\usepackage{stackengine}
\usepackage{needspace}
\usepackage{environ}
\newsavebox{\exercisebox}% just in case
\NewEnviron{ExerciseBox}{\par
\setbox\exercisebox=\vbox{\BODY}% measure height
\ifdim\ht\exercisebox>0.5\textheight
\needspace{2\baselineskip}% still want to avoid naked header
\else
\needspace{\ht\exercisebox}% to use \unvbox instead of \box
\fi
\unvbox\exercisebox}
\usepackage{showframe}% alignment tool
\begin{document}
\begin{ExerciseBox}
\begin{Exercise}
\Question Solve the following equations, giving exact answers.
\begin{tasks}(2)
\task $\dfrac{5}{x}=2$
\task $\dfrac{5x+6}{3}+\dfrac{4-x}{5}=3$
\end{tasks}
\Question Solve, giving your answers correct to 3 significant figures.
\begin{tasks}(2)
\task $\dfrac{x(x+1)^2}{3(x-1)}=x^2$
\task $\dfrac{2}{x+3}-\dfrac{1}{x-7}=1$
\end{tasks}
\Question Solve, giving your answers correct to 3 significant figures.
\begin{tasks}(2)
\task $\dfrac{x(x+1)^2}{3(x-1)}=x^2$
\task $\dfrac{2}{x+3}-\dfrac{1}{x-7}=1$
\end{tasks}
\Question Solve, giving your answers correct to 3 significant figures.
\begin{tasks}(2)
\task $\dfrac{x(x+1)^2}{3(x-1)}=x^2$
\task $\dfrac{2}{x+3}-\dfrac{1}{x-7}=1$
\end{tasks}
\Question Solve, giving your answers correct to 3 significant figures.
\begin{tasks}(2)
\task $\dfrac{x(x+1)^2}{3(x-1)}=x^2$
\task $\dfrac{2}{x+3}-\dfrac{1}{x-7}=1$
\end{tasks}
\Question Solve, giving your answers correct to 3 significant figures.
\begin{tasks}(2)
\task $\dfrac{x(x+1)^2}{3(x-1)}=x^2$
\task $\dfrac{2}{x+3}-\dfrac{1}{x-7}=1$
\end{tasks}
\needspace{2\baselineskip}% you may wan to patch the \Question command
\Question Solve, giving your answers correct to 3 significant figures.
\begin{tasks}(2)
\task $\dfrac{x(x+1)^2}{3(x-1)}=x^2$
\task $\dfrac{2}{x+3}-\dfrac{1}{x-7}=1$
\end{tasks}
\end{Exercise}
\end{ExerciseBox}
\noindent\rule{\textwidth}{25\baselineskip}
\begin{ExerciseBox}
\begin{Exercise}
\Question Solve the following equations, giving exact answers.
\begin{tasks}(2)
\task $\dfrac{5}{x}=2$
\task $\dfrac{5x+6}{3}+\dfrac{4-x}{5}=3$
\end{tasks}
\Question Solve, giving your answers correct to 3 significant figures.
\begin{tasks}(2)
\task $\dfrac{x(x+1)^2}{3(x-1)}=x^2$
\task $\dfrac{2}{x+3}-\dfrac{1}{x-7}=1$
\end{tasks}
\end{Exercise}
\end{ExerciseBox}
\end{document}