我正在尝试修改\answerline
以做两件事:
- 每个问题的答案标签可能不同;
- 将答案(仅答案而不是标签)以自己选择的颜色完成(这样
\SolutionEmphasis{}
做可能很方便,但我不知道如何利用它来实现上述 1.)。
理想情况下,最终的宏,调用它\solutionline
应该能够响应\solutionline{$H=$}{3}
并产生:
高度 = _____3______
其中 3 个颜色不同。
按照 Steven B. Segletes 的回答这问题,我尝试了以下但我现在明白这是行不通的。
\documentclass{exam}
\usepackage{xcolor}
\newcommand{\answerprompt}[1][\textbf{Answer:}]{#1}
\usepackage{xpatch}% http://ctan.org/pkg/etoolbox
\xpatchcmd{\answerline}% <cmd>
{\questionlabel}% <search>
{\answerprompt}% <replace>
{}{}% <success><failure>
\newcommand{\solutionline}[2]{\answerprompt{#1}\answerline[#2]}
\usepackage{xpatch}% http://ctan.org/pkg/etoolbox
\xpatchcmd{\answerline}% <cmd>
{\hfil #1}% <search>
{\hfil \color{blue}{#1}}% <replace>
{}{}% <success><failure>
\printanswers
\begin{document}
Hello!
\begin{questions}
\question Hello there! \answerline[Back at you!]
\question There! \answerline[Hey!]
\question Hey! \solutionline{H}{T}
\end{questions}
\end{document}
先感谢您!
答案1
使用以下定义\solutionline
:
\makeatletter
\newcommand{\solutionline}[3][blue]{%
\begingroup%
\xpatchcmd{\answerline}% <cmd>
{\ans@l~}% <search>
{\answerprompt[#2]~}% <replace>
{}{}% <success><failure>
\answerline[\textcolor{#1}{#3}]%
\endgroup%
}
\makeatother
完成 MWE:
\documentclass{exam}
\usepackage{xcolor}
\usepackage{xpatch}% http://ctan.org/pkg/etoolbox
\newcommand{\answerprompt}[1][\textbf{Answer:}]{#1}
\makeatletter
\newcommand{\solutionline}[3][blue]{%
\begingroup%
\xpatchcmd{\answerline}% <cmd>
{\ans@l~}% <search>
{\answerprompt[#2]~}% <replace>
{}{}% <success><failure>
\answerline[\textcolor{#1}{#3}]%
\endgroup%
}
\makeatother
\printanswers
\begin{document}
Hello!
\begin{questions}
\question Hello there! \answerline[Back at you!]
\question There! \answerline[Hey!]
\question Hey! \solutionline{H}{T}
\question Hey! \solutionline[green]{H}{green}
\question There! \answerline[Hey!]
\end{questions}
\end{document}