考试:如何让解决方案框跨越整个文本宽度,而不管问题级别如何?

考试:如何让解决方案框跨越整个文本宽度,而不管问题级别如何?

我想让任何解决方案框跨越任何问题/部分/子部分/子子部分的整个文本宽度。

\documentclass{exam}
\renewcommand{\solutiontitle}{\noindent\textbf{\underline{Answer:}}\par\noindent}
\printanswers

\begin{document}

\begin{questions}
\question Some question.

  \begin{parts}
  \part some part
    \begin{solution}
    I need this solution box to span the whole text width.
    \end{solution}

    \begin{subparts}
        \subpart another question
        \begin{solution}
            I need this solution box to span the whole text width.
        \end{solution}
    \end{subparts}

  \end{parts}
\end{questions}
\end{document}

在此处输入图片描述

答案1

为了使解决方案框与文本宽度一样宽,您可以将其括在\fullwidth{<solution>}命令中或使用EnvFullwidth环境。有关此内容的详细信息,请参阅exam文档

默认情况下,解决方案会打印在一个框中,该框的宽度等于当前问题(或部分、子部分或子子部分)的文本宽度。也就是说,解决方案左侧的缩进等于当前缩进级别。您可以通过将solutionsolutionorboxsolutionorlinessolutionordottedlines或环境包含在or命令solutionorgrid的参数中或or环境内来更改此设置\fullwidth\uplevelEnvFullwidthEnvUplevel

\fullwidth以下 MWE 演示了命令以及环境的用法EnvFullwidth

\documentclass{exam}
\renewcommand{\solutiontitle}{\noindent\textbf{\underline{Answer:}}\par\noindent}
\printanswers


\begin{document}

\begin{questions}
\question The \textbf{fullwidth} approach

  \begin{parts}
  \part some part
   \fullwidth{ \begin{solution}
    I need this solution box to span the whole text width.
    \end{solution}}

    \begin{subparts}
        \subpart another question
      \fullwidth{   \begin{solution}
            I need this solution box to span the whole text width.
        \end{solution}}
    \end{subparts}

  \end{parts}
\end{questions}

\begin{questions}
\question The \textbf{EnvFullwidth} approach

  \begin{parts}
  \part some part
  \begin{EnvFullwidth}
     \begin{solution}
        I need this solution box to span the whole text width.
      \end{solution}
   \end{EnvFullwidth}

    \begin{subparts}
        \subpart another question
        \begin{EnvFullwidth}
          \begin{solution}
            I need this solution box to span the whole text width.
          \end{solution}
        \end{EnvFullwidth}
    \end{subparts}

  \end{parts}
\end{questions}
\end{document}

在此处输入图片描述


要全局应用更改,您可以按如下方式定义自己的解决方案环境:

\documentclass{exam}
\renewcommand{\solutiontitle}{\noindent\textbf{\underline{Answer:}}\par\noindent}
\printanswers


\newenvironment{widesolution}{\begin{EnvFullwidth}\begin{solution}}{\end{solution}\end{EnvFullwidth}}

\begin{document}

\begin{questions}
\question The \textbf{new environment} approach

  \begin{parts}
  \part some part
   \begin{widesolution}
    I need this solution box to span the whole text width.
    \end{widesolution}

    \begin{subparts}
        \subpart another question
     \begin{widesolution}
            I need this solution box to span the whole text width.
        \end{widesolution}
    \end{subparts}

  \end{parts}
\end{questions}
\end{document}

为了删除上面两个例子中注释掉的垂直空白,我们可以使用手册第 8.8 节中描述的\printanswers命令:\ifprintanswers

8.8 根据是否打印解决方案而变化

\ifprintanswers如果您想要以除解决方案环境(参见第 8 节)、多项选择环境中的命令(参见第 5.5 节)和命令的可选参数(参见第 7.7 节)所提供的方式以外的方式改变考试中显示的内容\CorrectChoice,则提供\answerline此命令。您可以通过键入以下内容来使用此命令:

\ifprintanswers

Stuff to appear only when answers are being printed.

\else

Stuff to appear only when answers are not being printed.

\fi

下面是一个简短的 MWE,它引入了一个新环境,该环境仅在使用widesolution时才是全宽的。否则,环境等于环境,因此如果不使用,则不会引起任何额外的空白:\printanswerswidesolutionssolutions\printanswers

\documentclass[cancelspace]{exam}
\renewcommand{\solutiontitle}{\noindent\textbf{\underline{Answer:}}\par\noindent}
%\printanswers


\ifprintanswers
  \newenvironment{widesolution}{\begin{EnvFullwidth}\begin{solution}}{\end{solution}\end{EnvFullwidth}}
\else
    \newenvironment{widesolution}{\begin{solution}}{\end{solution}}
\fi



\begin{document}

\begin{questions}
\question The \textbf{new environment} approach

  \begin{parts}
  \part some part
   \begin{widesolution}
    I need this solution box to span the whole text width.
    \end{widesolution}

    \begin{subparts}
        \subpart another question
     \begin{widesolution}
            I need this solution box to span the whole text width.
        \end{widesolution}
    \end{subparts}

  \end{parts}
\end{questions}

\end{document}

在此处输入图片描述

相关内容