考试类别中有图形选项的多项选择题

考试类别中有图形选项的多项选择题

我正在使用创建多项选择题考試班但是我遇到了两个问题:1)。想要有两列选项,但默认显示为 A、C、B、D,2)。选项中的数字是底部对齐而不是顶部对齐。有什么建议吗?以下是我的 MWE:

\documentclass{exam}
\usepackage{multicol}
\usepackage{graphicx}
\begin{document}
    \begin{questions}
        \question
        \begin{minipage}[t]{0.65\linewidth}
        Consider the network graph shown in the figure, which of the following is NOT a \textit{tree} of this graph?
            \begin{multicols}{2}
                \begin{choices}
                    \choice
                        \includegraphics[scale=0.2]{example-image-a}
                    \choice
                        \includegraphics[scale=0.2]{example-image-b}
                    \choice
                        \includegraphics[scale=0.2]{example-image-c}
                    \CorrectChoice
                        \includegraphics[scale=0.2]{example-image-a}
                \end{choices}
            \end{multicols}
    \end{minipage}
    \hspace{2em}%
    \begin{minipage}[t]{0.35\linewidth}
        \vspace{-\baselineskip}
        \includegraphics[scale=0.4]{example-image-a}
    \end{minipage}
\end{questions}
\end{document}

运行上述代码后的输出如下: 在此处输入图片描述

然而,我希望有这样的东西: 在此处输入图片描述

答案1

这是一个选项:

\documentclass{exam}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{adjustbox}

\begin{document}
    \begin{questions}
        \question
        \begin{minipage}[t]{0.65\linewidth}
        Consider the network graph shown in the figure, which of the following is NOT a \textit{tree} of this graph?
                \begin{choices}
            \begin{multicols}{2}
                    \choice
                        \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-a}}
                    \choice
                        \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-b}}
            \end{multicols}\par
            \begin{multicols}{2}
                    \choice
                        \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-c}}
                    \CorrectChoice
                        \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-a}}
            \end{multicols}
                \end{choices}
    \end{minipage}\hfill%
        \begin{adjustbox}{minipage={0.30\linewidth},valign=t}
        \includegraphics[width=\linewidth]{example-image-a}
    \end{adjustbox}
\end{questions}
\end{document}

在此处输入图片描述

我用的是adjustbox包以获得所需的顶部对齐。对于编号模式,我使用了两个multicols环境,而不是一个。

我还改变了宽度\hbox 的scale选项。\includegraphicsand changed some spaces to prevent overfull

答案2

egreg 几乎可以解答所有问题。对于您的第一个问题,您可以使用 egereg 提供的解决方案:

%%------------------egreg's code starts-------------
\usepackage{environ,xparse}
\ExplSyntaxOn
\cs_undefine:N \choices
\cs_undefine:N \endchoices
\NewEnviron{choices}{%
  \par\nopagebreak
  \harish_dochoices:V \BODY
  \par
}
\tl_new:N \l_harish_choices_tl
\seq_new:N \l_harish_choices_seq
\seq_new:N \l_harish_choices_final_seq

\cs_new_protected:Npn \harish_dochoices:n #1
 {
  \setcounter{choice}{0}
  \tl_set:Nn \l_harish_choices_tl { #1 }
  \tl_replace_once:Nnn \l_harish_choices_tl { \CorrectChoice } { \choice* }
  \seq_set_split:NnV \l_harish_choices_seq { \choice } \l_harish_choices_tl
  \seq_pop_left:NN \l_harish_choices_seq \l_tmpa_tl
  \seq_set_map:NNn \l_harish_choices_final_seq \l_harish_choices_seq
   { \exp_not:n { \makechoice ##1 } }
  %\seq_map_inline:Nn \l_harish_choices_final_seq { \makebox[.5\linewidth][l]{##1}\hspace{0pt plus .3\linewidth} }
% }
    \seq_map_inline:Nn \l_harish_choices_final_seq
   {
    \makebox[.5\linewidth][l]{
      \parbox[t]{.45\linewidth}{\raggedright \hangindent1.5em ##1\strut}
    }\hspace{0pt plus .3\linewidth}
   }
 }
\cs_generate_variant:Nn \harish_dochoices:n { V }
\ExplSyntaxOff
\makeatletter
    \NewDocumentCommand{\makechoice}{s}
 {%
  \stepcounter{choice}
  \makebox[1.2em][l]{\IfBooleanT{#1}{\ifprintanswers\CorrectChoice@Emphasis\fi}\Alph{choice}.}
 }
\makeatother
\CorrectChoiceEmphasis{\bfseries\boldmath}

%%------------------egreg's code ends-------------

有一次,我在做一些试卷时遇到类似的问题,他帮助过我。

对于第二个问题,您可以加载adjustbox包(就像 Gonzalo 所做的那样),但要使用export选项。这将使诸如valignetc 之类的键可用于\includegraphics命令。因此您必须使用

\includegraphics[scale=0.2,valign=t]{example-image-a}

请记住,在这种情况下graphicx是由 加载的adjustbox

完整代码如下:

\documentclass{exam}
\usepackage[export]{adjustbox}

%%------------------egreg's code starts-------------
\usepackage{environ,xparse}
\ExplSyntaxOn
\cs_undefine:N \choices
\cs_undefine:N \endchoices
\NewEnviron{choices}{%
  \par\nopagebreak
  \harish_dochoices:V \BODY
  \par
}
\tl_new:N \l_harish_choices_tl
\seq_new:N \l_harish_choices_seq
\seq_new:N \l_harish_choices_final_seq

\cs_new_protected:Npn \harish_dochoices:n #1
 {
  \setcounter{choice}{0}
  \tl_set:Nn \l_harish_choices_tl { #1 }
  \tl_replace_once:Nnn \l_harish_choices_tl { \CorrectChoice } { \choice* }
  \seq_set_split:NnV \l_harish_choices_seq { \choice } \l_harish_choices_tl
  \seq_pop_left:NN \l_harish_choices_seq \l_tmpa_tl
  \seq_set_map:NNn \l_harish_choices_final_seq \l_harish_choices_seq
   { \exp_not:n { \makechoice ##1 } }
  %\seq_map_inline:Nn \l_harish_choices_final_seq { \makebox[.5\linewidth][l]{##1}\hspace{0pt plus .3\linewidth} }
% }
    \seq_map_inline:Nn \l_harish_choices_final_seq
   {
    \makebox[.5\linewidth][l]{
      \parbox[t]{.45\linewidth}{\raggedright \hangindent1.5em ##1\strut}
    }\hspace{0pt plus .3\linewidth}
   }
 }
\cs_generate_variant:Nn \harish_dochoices:n { V }
\ExplSyntaxOff
\makeatletter
    \NewDocumentCommand{\makechoice}{s}
 {%
  \stepcounter{choice}
  \makebox[1.2em][l]{\IfBooleanT{#1}{\ifprintanswers\CorrectChoice@Emphasis\fi}\Alph{choice}.}
 }
\makeatother
\CorrectChoiceEmphasis{\bfseries\boldmath}

%%------------------egreg's code ends-------------

\begin{document}
    \begin{questions}
        \question
        \begin{minipage}[t]{0.65\linewidth}
        Consider the network graph shown in the figure, which of the following is NOT a \textit{tree} of this graph?
            %\begin{multicols}{2}
                \begin{choices}
                    \choice
                        \includegraphics[scale=0.2,valign=t]{example-image-a}
                    \choice
                        \includegraphics[scale=0.2,valign=t]{example-image-b}
                    \choice
                        \includegraphics[scale=0.2,valign=t]{example-image-c}
                    \CorrectChoice
                        \includegraphics[scale=0.2,valign=t]{example-image-a}
                \end{choices}
            %\end{multicols}
    \end{minipage}
    \hfill%
    \begin{minipage}[t]{0.3\linewidth}
        \vspace{-\baselineskip}
        \includegraphics[width=\linewidth]{example-image-a}
    \end{minipage}
\end{questions}
\end{document}

在此处输入图片描述

如果您对类不感兴趣exam,我建议您使用exsheets对此类列表有本机支持的类。

相关内容