我尝试使用以下代码来制作多项选择题...但选项并非均匀分布在一行中...
我曾经\hfill
通过替换来使用\penalty -50\hskip 2em plus 2em\relax
...当选择占据单行时,它运行良好,但是当选择占据第二行时,结果就很糟糕...当选择占据多行时,我希望每行有两个选择...
\documentclass[12pt]{article}
\newcounter{choice}
%\renewcommand\thechoice{\Alph{choice}}
\renewcommand\thechoice{\alph{choice}}
\newcommand\choicelabel{\thechoice.}
\newenvironment{choices}%
{\list{\choicelabel}%
{\usecounter{choice}\def\makelabel##1{\hss\llap{##1}}%
\settowidth{\leftmargin}{W.\hskip\labelsep\hskip 2.5em}%
\def\choice{%
\item} % choice
\labelwidth\leftmargin\advance\labelwidth -\labelsep
\topsep=0pt
\partopsep=0pt}%
}%
{\endlist}
\newenvironment{oneparchoices}%
{%
\setcounter{choice}{0}%
\def\choice{%
\refstepcounter{choice}%
\ifnum\value{choice}>1\relax
\penalty -50\hskip 2em plus 2em\relax
\fi
\choicelabel
\nobreak\enskip
}% choice
% If we're continuing the paragraph containing the question,
% then leave a bit of space before the first choice:
\ifvmode\else\enskip\fi
\ignorespaces
}%
{}
\begin{document}
\begin{enumerate}
\item One of these things is not like the others; one of these things is not the same. Which one doesn't belong?
\begin{oneparchoices}
\choice George
\choice Paul
\choice John
\choice Ringo
\choice Socrates
\end{oneparchoices}
\item Which one doesn't belong?
\begin{oneparchoices}
\choice George
\choice Paul
\choice John
\choice Ringo
\choice Socrates
\end{oneparchoices}
\item One of these things is not like the others; one of these things is not the same. Which one doesn't belong?
\begin{choices}
\choice George
\choice Paul
\choice John
\choice Ringo
\choice Socrates
\end{choices}
\item What was the color of George Washinton's white horse?
\begin{choices}
\choice Green
\choice Yellow
\choice White
\end{choices}
\item One of these things is not like the others; one of these things
is not the same. Which one doesn't belong?
\begin{oneparchoices}
\choice George
\choice Paul
\choice John
\choice Ringo
\choice Socrates
\end{oneparchoices}
\item What was the color of George Washinton's white horse?
\begin{oneparchoices}
\choice Green
\choice Yellow
\choice White
\end{oneparchoices}
\item What was the color of George Washinton's white horse?
\begin{oneparchoices}
\choice Green
\choice Yellow
\choice White
\end{oneparchoices}
\end{enumerate}
\end{document}
答案1
我尝试解决您的问题。最大的问题是确定内容是否超过两行。我认为 atrivlist
无法实现这种想法。所以我决定使用 ahbox
和的组合vbox
。首先,我将 的内容保存oneparchoices
在 a 中\hbox
并测试宽度。如果宽度大于当前宽度,linewidth
则框将切换为vbox
。 的定义choise
允许所需的换行符。
\documentclass[12pt]{article}
\usepackage{showframe}
\usepackage{letltxmacro}
\usepackage{etoolbox}
\usepackage[]{enumitem}
\newlist{choices}{enumerate}{2}
\setlist[choices]{label=\alph*}
\newcounter{choice}
\renewcommand\thechoice{\alph{choice}}
\setcounter{choice}{0}
\makeatletter
\newenvironment{oneparchoices}%
{\ifvmode\leavevmode\else\par\unskip\fi%
\begingroup
\setcounter{choice}{0}%
\def\choice{%
\stepcounter{choice}%
\ifnumodd{\value{choice}}{\newline}{\hspace*{2.5em}}%
\ifnumgreater{\value{choice}}{1}%
{\hspace{3em}}{}%
\thechoice.\hspace*{.5em}\null
}
\setbox\z@\hbox\bgroup\ignorespaces%
}{%
\egroup%
\ifdimgreater{\wd\z@}{\linewidth}{%
\setbox\z@\vbox{\hsize=\linewidth\unhbox\z@}%
\makebox[\linewidth][l]{\box\z@}%
}%
{%
\makebox[\linewidth][l]{\box\z@}%
}%
\endgroup%
}%
\makeatother
\LetLtxMacro{\choice}{\item}
\begin{document}
\begin{enumerate}
\choice One of these things is not like the others; one of these things is not the same. Which one doesn't belong?%
\begin{oneparchoices}
\choice George
\choice Paul
\choice John
\choice Ringo
\choice Socrates
\end{oneparchoices}
\choice Which one doesn't belong?
\begin{oneparchoices}
\choice George
\choice Paul
\choice John
\choice Ringo
\choice Socrates
\end{oneparchoices}
\choice One of these things is not like the others; one of these things is not the same. Which one doesn't belong?
\begin{choices}
\choice George
\choice Paul
\choice John
\choice Ringo
\choice Socrates
\end{choices}
\choice What was the color of George Washinton's white horse?
\begin{choices}
\choice Green
\choice Yellow
\choice White
\end{choices}
\choice One of these things is not like the others; one of these things
is not the same. Which one doesn't belong?
\begin{oneparchoices}
\choice George
\choice Paul
\choice John
\choice Ringo
\choice Socrates
\end{oneparchoices}
\choice What was the color of George Washinton's white horse?
\begin{oneparchoices}
\choice Green
\choice Yellow
\choice White
\end{oneparchoices}
\choice What was the color of George Washinton's white horse?
\begin{oneparchoices}
\choice Green
\choice Yellow
\choice White
\end{oneparchoices}
\end{enumerate}
\end{document}
一些反馈将是善意的。