标题居中和 \newcommand 内的 \newpage 命令

标题居中和 \newcommand 内的 \newpage 命令

我想创作一本有三部分的谜题书,问题提示解决方案。 两个都LaTeX 社区特克斯帮助我弄清楚了这一点。

我想做两件事:

  1. 将零件名称置于其标题页的中央。
  2. 我希望每个问题和每个解决方案都从新的一页开始,但提示可以是连续的。

埃格尔的基本代码如下:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{mathtools}
\usepackage{environ}

\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}

\newcounter{problem}
\newenvironment{problem}[1]
{\refstepcounter{problem}%
{\textbf{Problem \theproblem\ (#1)}\par}\nopagebreak\noindent\ignorespaces}
{}

\makeatletter
\newtoks\late@hintstoks
\newtoks\late@solutiontoks

\NewEnviron{hints}{%
\toks@=\expandafter{\BODY}%
\protected@edef\@tempa{%
\the\late@hintstoks % the previous contents
\noexpand\late@hint{\theproblem}{\the\toks@}%
}%
\global\late@hintstoks=\expandafter{\@tempa}%
}
\NewEnviron{solution}{%
\toks@=\expandafter{\BODY}%
\protected@edef\@tempa{%
\the\late@solutiontoks % the previous contents
\noexpand\late@solution{\theproblem}{\the\toks@}%
}%
\global\late@solutiontoks=\expandafter{\@tempa}%
}
\newcommand{\late@hint}[2]{%
\paragraph*{Hints for problem #1}#2%
}
\newcommand{\late@solution}[2]{%
\subsubsection*{Solution for problem #1}#2%
}

\newcommand{\printhints}{%
\part{Hints}
\the\late@hintstoks
}
\newcommand{\printsolutions}{%
\part{Solutions}
\the\late@solutiontoks
}
\makeatother

\begin{document}

\part{Problems}
\section{Puzzle 1}
\begin{problem}{Pythagoras}
This problem is about Pythagoras' theorem
\begin{hints}
These are the hints about Pythagoras.
\end{hints}
\begin{solution}
Pythagoras' theorem is easy!
\end{solution}
\end{problem}
\section{Puzzle 2}
\begin{problem}{Riemann}
Prove the zeros of the $\zeta$ functions are on the critical line.
\begin{hints}
Try first with a few cases.
\end{hints}
\begin{solution}
Oh, well!
\end{solution}
\end{problem}

\printhints

\printsolutions

\end{document}

此问题也发布在 标题居中和 \newcommand 内的 \newpage 命令

答案1

sectsty您可以使用并添加来使零件居中

\usepackage{sectsty}
\partfont{\centering}

而为了在新页面上显示内容,您必须添加一些\clearpage/ \cleardoublepage(为了安全起见),正如我在代码中所标记的那样。

\documentclass{article}
\usepackage[english]{babel}
\usepackage{mathtools}
\usepackage{environ}
\usepackage{sectsty}
\partfont{\centering}

\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}

\newcounter{problem}
\newenvironment{problem}[1]
{\refstepcounter{problem}%
{\textbf{Problem \theproblem\ (#1)}\par}\nopagebreak\noindent\ignorespaces}
{\clearpage}                                          %%%<--- here

\makeatletter
\newtoks\late@hintstoks
\newtoks\late@solutiontoks

\NewEnviron{hints}{%
\toks@=\expandafter{\BODY}%
\protected@edef\@tempa{%
\the\late@hintstoks % the previous contents
\noexpand\late@hint{\theproblem}{\the\toks@}%
}%
\global\late@hintstoks=\expandafter{\@tempa}%
}
\NewEnviron{solution}{%
\toks@=\expandafter{\BODY\clearpage}%                   %%%<--- here
\protected@edef\@tempa{%
\the\late@solutiontoks % the previous contents
\noexpand\late@solution{\theproblem}{\the\toks@}%
}%
\global\late@solutiontoks=\expandafter{\@tempa}%
}
\newcommand{\late@hint}[2]{%
\paragraph*{Hints for problem #1}#2%
}
\newcommand{\late@solution}[2]{%
\subsubsection*{Solution for problem #1}#2%
}

\newcommand{\printhints}{%
\cleardoublepage                                                %%%<--- here
\part{Hints}
\the\late@hintstoks
}
\newcommand{\printsolutions}{%
\cleardoublepage                                                 %%%<--- here
\part{Solutions}
\the\late@solutiontoks
}
\makeatother

\begin{document}

\part{Problems}
\section{Puzzle 1}
\begin{problem}{Pythagoras}
This problem is about Pythagoras' theorem
\begin{hints}
These are the hints about Pythagoras.
\end{hints}
\begin{solution}
Pythagoras' theorem is easy!
\end{solution}
\end{problem}
\section{Puzzle 2}
\begin{problem}{Riemann}
Prove the zeros of the $\zeta$ functions are on the critical line.
\begin{hints}
Try first with a few cases.
\end{hints}
\begin{solution}
Oh, well!
\end{solution}
\end{problem}

\printhints

\printsolutions

\end{document}

在此处输入图片描述

答案2

\clearpage也使用 s 来在自己的页面上开始每个问题和解决方案。由于我觉得这可能是一项更长的工作,我只是从文章类切换到报告类,更准确地说是scrreprt从 KOMA 包切换到报告类。任何渴望了解标准类的人都可以取消注释emulatestandardclasses。但我们生活在现代。

\documentclass[%emulatestandardclasses
]{scrreprt}
\usepackage[english]{babel}
\usepackage{mathtools}
\usepackage{environ}

\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}

\newcounter{problem}
\newenvironment{problem}[1]
{\refstepcounter{problem}%
{\clearpage\noindent\textbf{Problem \theproblem\ (#1)}\medbreak}\nopagebreak\noindent\ignorespaces}
{\bigbreak}

\makeatletter
\newtoks\late@hintstoks
\newtoks\late@solutiontoks

\NewEnviron{hints}{%
\toks@=\expandafter{\BODY}%
\protected@edef\@tempa{%
\the\late@hintstoks % the previous contents
\noexpand\late@hint{\theproblem}{\the\toks@}%
}%
\global\late@hintstoks=\expandafter{\@tempa}%
}
\NewEnviron{solution}{%
\toks@=\expandafter{\BODY}%
\protected@edef\@tempa{%
\the\late@solutiontoks % the previous contents
\noexpand\late@solution{\theproblem}{\the\toks@}%
}%
\global\late@solutiontoks=\expandafter{\@tempa}%
}
\newcommand{\late@hint}[2]{%
\paragraph*{Hints for problem #1}#2%
}
\newcommand{\late@solution}[2]{%
\clearpage
\subsection*{Solution for problem #1}#2%
}

\newcommand{\printhints}{%
\part{Hints}
\the\late@hintstoks
}
\newcommand{\printsolutions}{%
\part{Solutions}
\the\late@solutiontoks
}
\makeatother

\begin{document}

\part{Problems}
\begin{problem}{Pythagoras}
This problem is about Pythagoras' theorem
\begin{hints}
These are the hints about Pythagoras.
\end{hints}
\begin{solution}
Pythagoras' theorem is easy!
\end{solution}
\end{problem}
\begin{problem}{Riemann}
Prove the zeros of the $\zeta$ functions are on the critical line.
\begin{hints}
Try first with a few cases.
\end{hints}
\begin{solution}
Oh, well!
\end{solution}
\end{problem}

\printhints

\printsolutions

\end{document}

我问了一些进一步的问题,以改善结果LaTeX 社区。欢迎各位有兴趣者参与讨论发展。

答案3

我搞清楚了第二部分。要将 \newpage 命令添加到 Solutions 部分,您需要在 \late@solution 环境中添加 \newpage 命令才能获得所需的效果。

\newcommand{\late@solution}[2]{%
  \subsubsection*{Solution for puzzle #1}#2%
  \newpage
}

为了使部分(及其标题)居中,我将文档类别更改为书籍,这样可以工作,但是它会弄乱所有部分的编号,并将所有内容解释为章节等。有办法解决这个问题吗?


相关内容