选项的多项选择题类型设置

选项的多项选择题类型设置

在下面的代码中,我们根据答案的长度以下列方式获取每个问题的答案 [1] (a) (b) (c) (d) 即 (4 列) [2] (a) (b) (c) (d) 即 (2 列)。很好....

这段代码中是否有任何更正,如果我想在一列中生成所有四个选项,我的意思是像(a)(b)(c)(d)(1 列)在我的问题库中有很多问题有一些长度合适的选项,并且不可能获得提到的 [1] 和 [2] 形式的输出。

请为该代码提供一些更好的解决方案,除了使用这个代码的几个问题之外,我几乎完成了我的工作。

\documentclass[12pt,a4paper]{exam}
\usepackage{amsmath,amsthm,amsfonts,amssymb,dsfont}
\setlength\parindent{0pt}
    %usage \choice{ }{ }{ }{ }
    %(A)(B)(C)(D)
    \newcommand{\fourch}[4]{
    \par
            \begin{tabular}{*{4}{@{}p{0.23\textwidth}}}
            (a)~#1 & (b)~#2 & (c)~#3 & (d)~#4
            \end{tabular}
    }

    %(A)(B)
    %(C)(D)
    \newcommand{\twoch}[4]{

            \begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
            (a)~#1 & (b)~#2
            \end{tabular}
    \par
            \begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
            (c)~#3 & (d)~#4
            \end{tabular}
    }

    %(A)
    %(B)
    %(C)
    %(D)
    \newcommand{\onech}[4]{
    \par
          (a)~#1 \par (b)~#2 \par (c)~#3 \par (d)~#4
    }

    \newlength\widthcha
    \newlength\widthchb
    \newlength\widthchc
    \newlength\widthchd
    \newlength\widthch
    \newlength\tabmaxwidth

    \setlength\tabmaxwidth{0.96\textwidth}
    \newlength\fourthtabwidth
    \setlength\fourthtabwidth{0.25\textwidth}
    \newlength\halftabwidth
    \setlength\halftabwidth{0.5\textwidth}

  \newcommand{\choice}[4]{%
  \settowidth\widthcha{AM.#1}\setlength{\widthch}{\widthcha}%
  \settowidth\widthchb{BM.#2}%
  \ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%
  \settowidth\widthchb{CM.#3}%
  \ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%
  \settowidth\widthchb{DM.#4}%
  \ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%
  \ifdim\widthch<\fourthtabwidth
    \fourch{#1}{#2}{#3}{#4}
  \else\ifdim\widthch<\halftabwidth
    \ifdim\widthch>\fourthtabwidth
      \twoch{#1}{#2}{#3}{#4}
    \else
      \onech{#1}{#2}{#3}{#4}
    \fi
  \fi\fi
}
\begin{document}
 \begin{questions}
\question If $a = 3 + i$ and $z = 2 - 3i$ then the points on the Argand diagram
representing az, 3az and - az are
\choice{Vertices of a right angled triangle}{ Vertices of an equilateral 
triangle}{Vertices of an isosceles triangle}{Collinear}
\question If z represents a complex number then $\arg (z) + \arg\left(\bar z\right)$ is 
\choice{$\dfrac{\pi}{4}$}{$\dfrac{\pi}{2}$}{0}{$\dfrac{\pi}{6}$}
\question If the amplitude of a complex number is $\dfrac{\pi}{2}$ then the number is
\choice{ purely imaginary}{purely real}{0}{neither real nor imaginary}
\question The value of $i + i^{22} + i^{23} + i^{24} + i^{25}$ is
\choice{i}{-i}{1}{-1}
\question The volume generated by 
rotating the triangle with vertices at
(0, 0), (3, 0) and (3, 3) about x-axis is
\choice{$18\pi$}{$2\pi$}{$36\pi$}{$9\pi$}\end{questions}
\end{document}

\end{document}

答案1

要获得单列答案,\ifdim需要稍微改变一下顺序。顺序应该是:如果最长答案适合 1/4,则放置四列,否则如果最长答案适合 1/2 宽度,则放置 2 列,否则放置 1 列。

此外,四个答案的长度分配不正确(b 用于 b、c 和 d)。MWE 进行了以下更正:

\documentclass[12pt,a4paper]{exam}
\usepackage{amsmath,amsthm,amsfonts,amssymb,dsfont}
\setlength\parindent{0pt}
    %usage \choice{ }{ }{ }{ }
    %(A)(B)(C)(D)
    \newcommand{\fourch}[4]{
    \par
            \begin{tabular}{*{4}{@{}p{0.23\textwidth}}}
            (a)~#1 & (b)~#2 & (c)~#3 & (d)~#4
            \end{tabular}
    }

    %(A)(B)
    %(C)(D)
    \newcommand{\twoch}[4]{

            \begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
            (a)~#1 & (b)~#2
            \end{tabular}
    \par
            \begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
            (c)~#3 & (d)~#4
            \end{tabular}
    }

    %(A)
    %(B)
    %(C)
    %(D)
    \newcommand{\onech}[4]{
    \par
          (a)~#1 \par (b)~#2 \par (c)~#3 \par (d)~#4
    }

    \newlength\widthcha
    \newlength\widthchb
    \newlength\widthchc
    \newlength\widthchd
    \newlength\widthch
    \newlength\tabmaxwidth

    \setlength\tabmaxwidth{0.96\textwidth}
    \newlength\fourthtabwidth
    \setlength\fourthtabwidth{0.25\textwidth}
    \newlength\halftabwidth
    \setlength\halftabwidth{0.5\textwidth}

  \newcommand{\choice}[4]{%
  \settowidth\widthcha{AM.#1}\setlength{\widthch}{\widthcha}%
  \settowidth\widthchb{BM.#2}%
  \ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%
  \settowidth\widthchc{CM.#3}%
  \ifdim\widthch<\widthchc\relax\setlength{\widthch}{\widthchc}\fi%
  \settowidth\widthchd{DM.#4}%
  \ifdim\widthch<\widthchd\relax\setlength{\widthch}{\widthchd}\fi%
  \ifdim\widthch<\fourthtabwidth
    \fourch{#1}{#2}{#3}{#4}
  \else\ifdim\widthch<\halftabwidth
      \twoch{#1}{#2}{#3}{#4}
    \else
      \onech{#1}{#2}{#3}{#4}
    \fi
  \fi
}
\begin{document}
 \begin{questions}
\question If $a = 3 + i$ and $z = 2 - 3i$ then the points on the Argand diagram
representing az, 3az and - az are
\choice{Vertices of a right angled triangle}{ Vertices of an equilateral 
triangle}{Vertices of an isosceles triangle}{Collinear}
\question If z represents a complex number then $\arg (z) + \arg\left(\bar z\right)$ is 
\choice{$\dfrac{\pi}{4}$}{$\dfrac{\pi}{2}$}{0}{$\dfrac{\pi}{6}$}
\question If the amplitude of a complex number is $\dfrac{\pi}{2}$ then the number is
\choice{ purely imaginary}{purely real}{0}{neither real nor imaginary}
\question The value of $i + i^{22} + i^{23} + i^{24} + i^{25}$ is
\choice{i}{-i}{1}{-1}
\question The volume generated by 
rotating the triangle with vertices at
(0, 0), (3, 0) and (3, 3) about x-axis is
\choice{$18\pi$}{$2\pi$}{$36\pi$}{$9\pi$}
\question A question with very long answers 
\choice{This answer is very long and will need the full width of the page to display which leads to a single column}{This answer, like the first, is very long and will need the full width of the page to display which leads to a single column}{This answer, like the second is very long and will need the full width of the page to display which leads to a single column}{This answer, like the third, is very long and will need the full width of the page to display which leads to a single column}
\end{questions}
\end{document}

请注意,您的 MWE 有两个\end{document}语句。

备注:问题不太清楚(我希望这个解决方案正是您所需要的)。为了便于将来参考,请提供一个出错的示例,在这种情况下,这是一个答案较长的问题。

相关内容