练习在页边,提示和解答在最后

练习在页边,提示和解答在最后

我使用答案包将问题放在文本中,将提示和解决方案放在文档末尾。现在我喜欢使用 Tufte 书籍风格,将小练习放在页边距中,同时在文档末尾保留提示和解决方案。我尝试将练习放在页边距中,但不起作用。下面的 MWE 详细解释了这一点。

\usepackage{answers}
\Newassociation{solution}{Solution}{ans}
\Newassociation{hint}{Hint}{hint}
\newtheorem{exercise}{Ex.}

\renewcommand{\Hintlabel}[1]{\textbf{h.#1.}}
\renewcommand{\Solutionlabel}[1]{\textbf{s.#1.}}
\begin{document}

\Opensolutionfile{hint}
\Opensolutionfile{ans}

\section{Test}
\label{sec:sec-1}


With the answer package we can put hints and answers at the end of the doc, see below.
\begin{exercise}
What is $2+2$?
\begin{hint}
Why is this the same as $1+1+1+1$?
\end{hint}
\begin{solution}
4
\end{solution}
\end{exercise}

现在我喜欢使用 Tufte 书籍风格,将练习的编号和文本放在页边空白处,将提示和答案放在文档末尾,就像上面的 $2+2$ 示例一样。例如:

Let us practice with division. \sidenote{\textbf{Ex. 2} What is $21/7$?}`. More text, blah blah blah blah blah \sidenote{\textbf{Ex. 3} what is $48/6$?}.

但是,这不适用于答案包,因为使用它需要将提示和解决方案放在练习环境中。 而 marginpar 不支持这一点。 换句话说,这不起作用:

\begin{verbatim}
\marginpar{
\begin{exercise}
What is $2+2$?
\begin{solution}
 4
\end{solution}
\end{exercise}
}
\end{verbatim}

那么,还有其他方法可以获得我的练习 2 和 3 所演示的功能吗?任何帮助都非常感谢。

\Closesolutionfile{hint}
\Closesolutionfile{ans}
\subsection*{Hints}
\input{hint}
\subsection*{Solutions}
\input{ans}

\end{document}

答案1

为用户提供的一个可能的解决方案xsim

\usepackage{lipsum}
\usepackage{xsim}
\usepackage{needspace}

\DeclareExerciseProperty{hint}

% we'll use a description list for the hints:
\newcommand\printhints{%
  \begin{description}
    \ForEachUsedExerciseByType{%
      \GetExercisePropertyT{hint}
        {\item[##3]####1}%
    }%
  \end{description}
}

\newcommand\hint[1]{\SetExerciseProperty{hint}{#1}}

\newsavebox\exercisebox
\DeclareExerciseEnvironmentTemplate{margin}{%
  \begin{lrbox}{\exercisebox}
    \textbf{\GetExerciseProperty{counter}} %
    \IfExercisePropertySetT{subtitle}{(\GetExerciseProperty{subtitle}) }%
}{%
  \end{lrbox}%
  \marginpar{\raggedright\unhbox\exercisebox}%
}

\DeclareExerciseEnvironmentTemplate{enumerate}
  {\begin{description}\item[\GetExerciseProperty{counter}]}
  {\end{description}}

\xsimsetup{
  exercise/template = margin ,
  solution/template = enumerate ,
  exercise/the-counter = \arabic{exercise}.
}

\begin{document}

\section{Problems}
% set hint through option:
\begin{exercise}[subtitle=Pythagoras,hint=This is a hint to the first problem.]
  This is the first problem.
\end{exercise}
\begin{solution}
  This is the solution to the first problem.
\end{solution}
\lipsum[2]

\begin{exercise}[subtitle=Another Problem]
  This is the second problem.
\end{exercise}
\begin{solution}
  This is the solution to the second problem.
\end{solution}
\lipsum[3]

% set hint with custom command:
\begin{exercise}
  This is the third problem.
  \hint{This is a hint to the third problem.}
\end{exercise}
\begin{solution}
  This is the solution to the third problem.
\end{solution}
\lipsum[4]

\section{Hints}
\printhints

\section{Solutions}
\printsolutions[headings=false]

\end{document}

在此处输入图片描述

答案2

你可以试试这个老把戏。我在 stack exchange 中整理了这段代码。

我不是专家,但我成功地完成了清单上的练习并给出了关键答案。

\documentclass{exam}
\usepackage{multicol}
\usepackage{amsmath}

\printanswers
\unframedsolutions

\newbox\allanswers
\setbox\allanswers\hbox{}

\renewenvironment{solution}{\noindent\global\setbox\allanswers=\hbox\bgroup\unhbox\allanswers{\egroup}

\newcommand{\showallanswers}{\noindent\unhbox\allanswers}


\begin{document}
\begin{multicols}{2}
\setlength{\columnsep}{20pt}
\setlength{\columnseprule}{0.01pt}

\begin{questions}

\question this is question 1

    \begin{parts}
\item item a
        \begin{solution}
        solution of item a
        \end{solution}

\item item b
        \begin{solution}
        solution of item b
        \end{solution}

\item item c
        \begin{solution}
        solution of item c
        \end{solution}
\item item d
        \begin{solution}
        ~solution of item d
        \end{solution}
    \end{parts}

\question this is question 2
        \begin{solution}
         $\dfrac{1}{2}$
         
        \end{solution}

\question this is question 3

    \begin{parts}
\item item a
        \begin{solution}
        solution of item a
        \end{solution}

\item item b
        \begin{solution}
        solution of item b
        \end{solution}

\item item c
        \begin{solution}
        solution of item c
        \end{solution}
\item item d
        \begin{solution}
        solution of item d
        \end{solution}
    \end{parts}
    
\question this is question 4
        \begin{solution}
        this is a long long long long long long long long long long long long long solution for question 4
        \end{solution}

\end{questions}
\end{multicols}

\vskip20pt
\begin{center}
{\Huge \textsc{Answer Key}}
\end{center}

\begin{multicols}{2}
\setlength{\columnsep}{20pt}
\setlength{\columnseprule}{0.01pt}

\showallanswers
\end{multicols}
\end{document}

答案3

我找到了这个技巧,但我仍然好奇地想看到更好的答案。

\begin{exercise}\label{ex:1}
\marginpar{{\cref{ex:1} What is $2+2$?}
\begin{hint}
Why is this the same as $1+1$?
\end{hint}
\begin{solution}
4
\end{solution}
\end{exercise}

相关内容