間隔良好的多項選擇選項

間隔良好的多項選擇選項

我正在使用 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*與其中之一結合使用\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}

相關內容