![我如何才能将 A、B、C、D 键的 exam-randomizechoices 对齐?](https://linux22.com/image/470160/%E6%88%91%E5%A6%82%E4%BD%95%E6%89%8D%E8%83%BD%E5%B0%86%20A%E3%80%81B%E3%80%81C%E3%80%81D%20%E9%94%AE%E7%9A%84%20exam-randomizechoices%20%E5%AF%B9%E9%BD%90%EF%BC%9F.png)
\documentclass[12pt,a4paper,answers]{exam}
\usepackage{amsmath}
\usepackage[randomize,overload]{exam-randomizechoices}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{%
\node[shape=circle, draw, minimum size=1.5em, inner sep=0pt , thick] (char) {#1};}}
\renewcommand\choicelabel{\circled{\Alph{choice}}}
\renewcommand{\questionshook}{%
\settowidth{\leftmargin}{0pt}}
\renewcommand{\choiceshook}{\settowidth{\leftmargin}{\circled{W}.\hskip\labelsep\hskip 0em}}
\newcommand{\correctchoicelabel}{\fbox{\thechoice}}
\CorrectChoiceEmphasis{\renewcommand{\choicelabel}{\correctchoicelabel}}
\usepackage[left=1.7cm,right=1.7cm,top=1.5cm,bottom=2cm]{geometry}
\begin{document}
\section{Questions}
\begin{questions}
\question What is 2+2?
\begin{oneparchoices}
\choice \makebox[.2\textwidth][l]{1}
\CorrectChoice \makebox[.2\textwidth][l]{4}
\choice \makebox[.2\textwidth][l]{2}
\choice \makebox[.2\textwidth][l]{3}
\end{oneparchoices}
\question What is 2+2?
\begin{oneparchoices}
\choice \makebox[.2\textwidth][l]{1}
\CorrectChoice \makebox[.2\textwidth][l]{4}
\choice \makebox[.2\textwidth][l]{2}
\choice \makebox[.2\textwidth][l]{3}
\end{oneparchoices}
\question What is the result of $y = x^3 - 3x^2 + 7x - 1$?
\begin{oneparchoices}
\choice \makebox[.4\textwidth][l]{some thing}
\CorrectChoice \makebox[.4\textwidth][l]{$a^2 + b^2 = c^2$}
\choice \makebox[.4\textwidth][l]{$a^2 + b^2 = c^2$}
\choice \makebox[.4\textwidth][l]{$a^2 + b^2 = c^2$}
\end{oneparchoices}
\question What is 2+2?
\begin{choices}
\choice Very long text Very long text Very long text
\CorrectChoice Very long text Very long text Very long text
\choice Very long text Very long text Very long text
\choice Very long text Very long text Very long text
\end{choices}
\end{questions}
\subsection{Keys}
\centering
\printkeytable
\end{document}
在这种情况下,键 A、B、C、D 排在两列中,例如问题 3,我想将键 B(某些东西)和键 D(a^2 + b^2 = c^2)对齐,以便与两个问题 1 和 2 的键 C 在同一行。我该怎么做?
答案1
请注意,这oneparchoices
是一个段落。它只是看起来像一个表格,因为所有条目的宽度都相同。首先,您需要将其设置\correctchoicelabel
为与相同的宽度choicelabel
。当设置两列时,宽度包括缺少的列标签和列之间添加的任何间隙。反复试验是您最好的选择。行末的空格似乎会导致随机变化。
几何与考试类别不兼容,考试类别处理其自己的边距(参见\extrawidth
第 26 页)。
\documentclass[12pt,a4paper,answers]{exam}
\usepackage{amsmath}
\usepackage[randomize,overload]{exam-randomizechoices}
\usepackage{tikz}
\usepackage{showframe}
\newlength{\choicewidth}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{%
\node[shape=circle, draw, minimum size=1.5em, inner sep=0pt , thick] (char) {#1};}}
\renewcommand\choicelabel{\circled{\Alph{choice}}}
\settowidth{\choicewidth}{\choicelabel}
\renewcommand{\questionshook}{\settowidth{\leftmargin}{0pt}}
\renewcommand{\choiceshook}{\setlength{\labelwidth}{\choicewidth}
\setlength{\leftmargin}{\dimexpr \labelwidth+\labelsep}}
\newcommand{\correctchoicelabel}{\makebox[\choicewidth]{\fbox{\thechoice}}}
\CorrectChoiceEmphasis{\renewcommand{\choicelabel}{\correctchoicelabel}}
%\usepackage[left=1.7cm,right=1.7cm,top=1.5cm,bottom=2cm]{geometry}
\begin{document}
\section{Questions}
\begin{questions}
\question What is 2+2?
\begin{oneparchoices}
\choice \makebox[.2\linewidth][l]{1}%
\CorrectChoice \makebox[.2\linewidth][l]{4}%
\choice \makebox[.2\linewidth][l]{r}%
\choice \makebox[.2\linewidth][l]{r}%
\end{oneparchoices}
\question What is 2+2?
\begin{oneparchoices}
\choice \makebox[.2\linewidth][l]{1}%
\CorrectChoice \makebox[.2\linewidth][l]{4}%
\choice \makebox[.2\linewidth][l]{2}%
\choice \makebox[.2\linewidth][l]{3}%
\end{oneparchoices}
\question What is the result of $y = x^3 - 3x^2 + 7x - 1$?
\begin{oneparchoices}
\choice \makebox[.485\linewidth][l]{some thing}%
\CorrectChoice \makebox[.485\linewidth][l]{$a^2 + b^2 = c^2$}%
\choice \makebox[.485\linewidth][l]{$a^2 + b^2 = c^2$}%
\choice \makebox[.485\linewidth][l]{$a^2 + b^2 = c^2$}%
\end{oneparchoices}
\question What is 2+2?
\begin{choices}
\choice Very long text Very long text Very long text
\CorrectChoice Very long text Very long text Very long text
\choice Very long text Very long text Very long text
\choice Very long text Very long text Very long text
\end{choices}
\end{questions}
\subsection{Keys}
\centering
\printkeytable
\end{document}