我正在使用 LaTeX 进行考试,并使用以下命令进行多项选择:
\newcommand{\mc}[5]{(\textbf{A}) #1 \qquad \qquad (\textbf{B}) #2 \qquad \qquad (\textbf{C}) #3 \qquad \qquad (\textbf{D}) #4 \qquad \qquad (\textbf{E}) #5}
但是,对于较小的答案选项(例如 1 或 2)或较长的答案选项(例如名称等),答案选项并不适合整个屏幕,因为我已用 硬编码了每个选项之间的空格\qquad
。
有没有办法可以自动使选项正确分布,以便它们完全适合整个页面?
提前致谢。
答案1
以下是使用该tasks
包的替代方法:
\documentclass{article}
\usepackage{tasks}
\setlength{\parindent}{0pt}
\begin{document}
\textbf{Question}: Here is the question text. Answers are arranged in 4 columns.
\begin{tasks}(4)
\task first answer
\task second answer
\task third answer
\task fourth answer
\end{tasks}
\bigskip
\textbf{Question}: Here is the question text. Answers are arranged in 2 columns.
\begin{tasks}(2)
\task first answer
\task second answer
\task third answer
\task fourth answer
\end{tasks}
\bigskip
\textbf{Question}: Here is the question text. Answers are arranged in 2 columns and are longer than a single line.
\begin{tasks}(2)
\task first answer first answer first answer first answer
\task second answer second answer second answer
\task third answer
\task fourth answer
\end{tasks}
\end{document}
如果您希望答案分布在整个文本宽度上,则可以使用tabularx
以下方法:(红色垂直线表示文本块的宽度)。请注意,使用此方法,第一列和第二列之间的空间以及倒数第二列和最后一列之间的空间将大于其他列之间的空间。(另请参阅此评论)
\documentclass{article}
\usepackage{tabularx}
\setlength{\parindent}{0pt}
\begin{document}
\textbf{Question}: Here is the question text. Answers are arranged in 4 columns and take up the entire textwidth.
\begin{tabularx}{\textwidth}{@{}X>{\centering\arraybackslash}X>{\centering\arraybackslash}X>{\raggedleft\arraybackslash}X@{}}
\textbf{A} first answer &
\textbf{B} second answer &
\textbf{C} third answer &
\textbf{D} fourth answer
\end{tabularx}
\end{document}
tabular*
与 one 结合使用\extracolsep{\fill}
可以实现以下输出。此处,相邻列之间的水平空白将相等。如果您的答案太长并且需要换行,您可能需要改为p
键入列。还请注意,使用此方法,每个答案占用的宽度是不同的。
\documentclass{article}
\setlength{\parindent}{0pt}
\begin{document}
\textbf{Question}: Here is the question text. Answers are arranged in 4 columns and take up the entire textwidth.
\setlength{\tabcolsep}{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ccccc}
\textbf{A} 1 &
\textbf{B} 2 &
\textbf{C} 3 &
\textbf{D} 4 &
\textbf{E} 5
\end{tabular*}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ccccc}
\textbf{A} 1 &
\textbf{B} 2 &
\textbf{C} 3 &
\textbf{D} 4 &
\textbf{E} longer text
\end{tabular*}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ccccc}
\textbf{A} 1 &
\textbf{B} long text &
\textbf{C} 3 &
\textbf{D} 4 &
\textbf{E} longer text
\end{tabular*}
\end{document}
答案2
我确信有几种方法。我建议使用 TikZ 方法,因为它比较灵活。我们可以为此编写一个新命令。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\centerline{\LARGE\bfseries\textcolor{blue}{TIKZ for multiple choices}}
\vspace*{1cm}
\noindent{\bfseries Question 1.} This question has $2$ choices.
\noindent\begin{tikzpicture}
\pgfmathsetmacro{\a}{\textwidth}
\path[font=\bfseries,blue]
(0,0) node{A. $x=1$}
++(0:\a/2 pt) node{B. $x=6$};
\end{tikzpicture}
\noindent{\bfseries Question 2.} This question has $3$ choices.
\noindent\begin{tikzpicture}
\pgfmathsetmacro{\a}{\textwidth}
\path[n/.style={font=\bfseries,circle,draw=blue,fill=gray!30},inner sep=1pt]
(0,0) node[n]{A} +(0:1) node{$m=3$}
++(0:\a/3 pt) node[n]{B} +(0:1) node{$m=4$}
++(0:\a/3 pt) node[n]{C} +(0:1) node{$m=3$};
\end{tikzpicture}
\noindent{\bfseries Question 3.} This question has $4$ choices.
\noindent\begin{tikzpicture}
\pgfmathsetmacro{\a}{\textwidth}
\path[font=\bfseries,blue,right]
(0,0) node{A. $x=1$}
++(0:\a/4 pt) node{B. $x=6$}
++(0:\a/4 pt) node{C. $x=8$}
++(0:\a/4 pt) node{D. $x=6688$};
\end{tikzpicture}
\noindent{\bfseries Question 4.} This question also has $4$ choices. You can see choices of Question $3$ and Question $4$ are vertically aligned.
\noindent\begin{tikzpicture}
\pgfmathsetmacro{\a}{\textwidth}
\path[font=\bfseries,magenta,right]
(0,0) node{A. $y=11$}
++(0:\a/4 pt) node{B. $y=66$}
++(0:\a/4 pt) node{C. $y=88$}
++(0:\a/4 pt) node{D. $y=668866$};
\end{tikzpicture}
\noindent{\bfseries Question 5.} This question also has $4$ choices with other arrangement.
\noindent\begin{tikzpicture}
\pgfmathsetmacro{\a}{\textwidth}
\path[font=\bfseries,right]
(0,0) node[blue] {A. Blue}
+(0:\a/2 pt) node[red] {B. Red}
++(-90:.5) node[violet] {C. Violet}
+(0:\a/2 pt) node[orange] {D. Orange};
\end{tikzpicture}
\end{document}