適切な間隔で配置された複数選択オプション

適切な間隔で配置された複数選択オプション

私は 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次のようにします。(赤い縦線はテキストブロックの幅を示します)。この方法では、最初の列と2番目の列の間、および最後から2番目の列と最後の列の間のスペースが、他の列間のスペースよりも大きくなることに注意してください。(参照:このコメント

ここに画像の説明を入力してください

\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}

関連情報