Code: Select all
\documentclass[a4paper]{article}
\usepackage{ifthen}
\usepackage{calc}
%usage \choice{ }{ }{ }{ }
%(A)(B)(C)(D)
\newcommand{\fourch}[4]{
\begin{tabular}{*{4}{@{}p{0.23\textwidth}}}
(A)~#1 & (B)~#2 & (C)~#3 & (D)~#4
\end{tabular}
}
%(A)(B)
%(C)(D)
\newcommand{\twoch}[4]{
\begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
(A)~#1 & (B)~#2
\end{tabular}
\par
\begin{tabular}{*{2}{@{}p{0.46\textwidth}}}
(C)~#3 & (D)~#4
\end{tabular}
}
%(A)
%(B)
%(C)
%(D)
\newcommand{\onech}[4]{
(A)~#1 \\ (B)~#2 \\ (C)~#3 \\ (D)~#4
}
\newlength\widthcha
\newlength\widthchb
\newlength\widthchc
\newlength\widthchd
\newlength\widthch
\newlength\tabmaxwidth
\setlength\tabmaxwidth{0.96\textwidth}
\newlength\fourthtabwidth
\setlength\fourthtabwidth{0.25\textwidth}
\newlength\halftabwidth
\setlength\halftabwidth{0.5\textwidth}
\newcommand{\choice}[4]{
\settowidth\widthcha{AM.#1}\setlength{\widthch}{\widthcha}
\settowidth\widthchb{BM.#2}
\ifthenelse{\widthch<\widthchb}{\setlength{\widthch}{\widthchb}}{}
\settowidth\widthchb{CM.#3}
\ifthenelse{\widthch<\widthchb}{\setlength{\widthch}{\widthchb}}{}
\settowidth\widthchb{DM.#4}
\ifthenelse{\widthch<\widthchb}{\setlength{\widthch}{\widthchb}}{}
\ifthenelse{\widthch<\fourthtabwidth}{\fourch{#1}{#2}{#3}{#4}}
{\ifthenelse{\widthch<\halftabwidth\and\widthch>\fourthtabwidth}{\twoch{#1}{#2}{#3}{#4}}
{\onech{#1}{#2}{#3}{#4}}}
}
\begin{document}
Question:
\choice{1}{2}{3}{4}
\par
Another Question:
\choice{hello world, hello wo}{hello world, h}{hello world, hello wd}{hello world, hello world}
\par
Third Question:
\choice{hello world, hello hello world,hello world,hello world,hello world,hello world,hello world,hello world,hello world,hello world,hello world,hello world,}{hello world, h}{hello world, hello wd}{hello world, hello world}
\end{document}
- Why does the third question's choice A is indent? But all the other choices were aligned correctly, any way to fix this?
- What does AM BM CM DM means?