thmtools 答案列表

thmtools 答案列表

我已经为带有练习表的表格创建了这样的文件。

\documentclass[12pt]{scrartcl}
\usepackage{amsthm, thmtools}
\usepackage{blindtext}

\declaretheoremstyle[
  headfont={\normalsize\bfseries},
  spaceabove=10pt,
  spacebelow=10pt
]{exstyle}
\declaretheorem[style=exstyle, title={Exercise}, numberwithin=section]{myexercise}

\declaretheoremstyle[
  headfont={\normalsize\bfseries},
  spaceabove=10pt,
  spacebelow=10pt
]{ansstyle}
\declaretheorem[style=ansstyle, title={}, numberwithin=section]{myanswer}



\begin{document}

\section{First section}

\blindtext

\begin{myexercise}
  This is the first exercise.
\end{myexercise}
\begin{myanswer}
  The answer to the first exercise. It's shown here but it shouldn't be! Pls look at the end of the page.
\end{myanswer}

\begin{myexercise}
  This is the second exercise.
\end{myexercise}
\begin{myanswer}
  The answer to the second exercise. It's shown here but it shouldn't be! Pls look at the end of the page.
\end{myanswer}

\blindtext

Here (at the end of the section) I want to have a command smth like showallanswers, which will print the list:

\textbf{Answers for exercise in first section:}

1.1 The answer to the first exercise.

1.2 The answer to the second exercise.

Exercises in the second section will have numeration from 1.1 again.

\end{document}

MWE 这样做:

在此处输入图片描述

如何创建一个命令,将答案列表放在每个部分的末尾?

答案1

您可以使用该包endfloat并将环境声明myanswer为延迟浮点。然后只需\processdelayedfloats在每个下一部分之前调用即可。您甚至可以重新定义一个\mysection可以自动执行此操作的命令。

\documentclass[12pt]{scrartcl}
\usepackage{amsthm, thmtools}
\usepackage{blindtext}
\usepackage[nomarkers]{endfloat}

\declaretheoremstyle[
  headfont={\normalsize\bfseries},
  spaceabove=10pt,
  spacebelow=10pt
]{exstyle}
\declaretheorem[style=exstyle, title={Exercise}, numberwithin=section]{myexercise}

\declaretheoremstyle[
  headfont={\normalsize\bfseries},
  spaceabove=10pt,
  spacebelow=10pt
]{ansstyle}
\declaretheorem[style=ansstyle, title={}, numberwithin=section]{myanswer}

\DeclareDelayedFloat{myanswer}{Answer}
\SetupDelayedFloat{myanswer}{nolist}

% Allow multiple float on the same page
\renewcommand\efloatseparator{\mbox{}}
% No break page before the floats.
\renewcommand\efloatbegin{}

\newcommand{\shallowanswer}{
\paragraph{Answers for exercise in first section:}
\processdelayedfloats
}
\begin{document}


\section{First section}

\blindtext

\begin{myexercise}
  This is the first exercise.
\end{myexercise}
\begin{myanswer}
  The answer to the first exercise. It's shown here but it shouldn't be! Pls look at the end of the page.
\end{myanswer}

\begin{myexercise}
  This is the second exercise.
\end{myexercise}
\begin{myanswer}
  The answer to the second exercise. It's shown here but it shouldn't be! Pls look at the end of the page.
\end{myanswer}

\blindtext

\shallowanswer
\end{document}

在此处输入图片描述

相关内容