I've been a user of this place for a long time and searched several solutions about typing latex correctly.

I've tried to write a simple exam paper and similar to this @Phil Hirschorn's answer like this and this. I have problems with making 2 columns using the mcq tests.

I really like making a simple exam to look like this:

enter image description here

and when I use \showallanswers we print this header

enter image description here

Any suggestion?


% Accumulate the answers. Unmodified from Phil Hirschorn's answer % Showing Solutions of the Questions "separately" \newbox\allanswers \setbox\allanswers=\vbox{}

\newenvironment{answer} {% \global\setbox\allanswers=\vbox\bgroup \unvbox\allanswers }% {% \bigbreak \egroup }

\newcommand{\showallanswers}{\par\unvbox\allanswers} % End Phil's answer

% Is there a better way? \newcommand*{\getanswer}5{% \ifthenelse{\equal{#5}{a}} {\begin{answer}\thequestion. (a)~#1\end{answer}} {\ifthenelse{\equal{#5}{b}} {\begin{answer}\thequestion. (b)~#2\end{answer}} {\ifthenelse{\equal{#5}{c}} {\begin{answer}\thequestion. (c)~#3\end{answer}} {\ifthenelse{\equal{#5}{d}} {\begin{answer}\thequestion. (d)~#4\end{answer}} {\begin{answer}\textbf{\thequestion. (#5)~Invalid answer choice.}\end{answer}}}}} }

\setlength\parindent{0pt} %usage \choice{ }{ }{ }{ } %(A)(B)(C)(D) \newcommand{\fourch}5{ \par \begin{tabular}{*{4}{@{}p{0.23\textwidth}}} (a)~#1 & (b)~#2 & (c)~#3 & (d)~#4 \end{tabular} \getanswer{#1}{#2}{#3}{#4}{#5} }

%(A)(B) %(C)(D) \newcommand{\twoch}5{ \par \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} \getanswer{#1}{#2}{#3}{#4}{#5} }

%(A) %(B) %(C) %(D) \newcommand{\onech}5{ \par (a)~#1 \par (b)~#2 \par (c)~#3 \par (d)~#4 \getanswer{#1}{#2}{#3}{#4}{#5} }

\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}5{% \settowidth\widthcha{AM.#1}\setlength{\widthch}{\widthcha}% \settowidth\widthchb{BM.#2}% \ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi% \settowidth\widthchb{CM.#3}% \ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi% \settowidth\widthchb{DM.#4}% \ifdim\widthch<\widthchb\relax\setlength{\widthch}{\widthchb}\fi%

% These if statements were bypassing the \onech option. % \ifdim\widthch<\fourthtabwidth % \fourch{#1}{#2}{#3}{#4}{#5} % \else\ifdim\widthch<\halftabwidth % \ifdim\widthch>\fourthtabwidth % \twoch{#1}{#2}{#3}{#4}{#5} % \else % \onech{#1}{#2}{#3}{#4}{#5} % \fi\fi\fi}

% Allows for the \onech option. \ifdim\widthch>\halftabwidth \onech{#1}{#2}{#3}{#4}{#5} \else\ifdim\widthch<\halftabwidth \ifdim\widthch>\fourthtabwidth \twoch{#1}{#2}{#3}{#4}{#5} \else \fourch{#1}{#2}{#3}{#4}{#5} \fi\fi\fi}



\noindent{\bf Ma 12 Long Test 1\hfill 9 February 2017}


\begin{questions} \question Um capacitor $C$ é submetido a uma tensão $V$. A energia armazenada no capacitor é igual a: \choice{$CV^2$}{$0.5CV^2$}{$2CV^2$}{$CV$}{b} \question Uma tensão V é aplicada a um circuito RL em série. A corrente em regime permanente é igual a: \choice{$V/R$}{$V/L$}{$\dfrac{V}{\sqrt{R^2+L^2}}$}{zero}{a} \question If the amplitude of a complex number is $\dfrac{\pi}{2}$ then the number is \choice{purely imaginary}{purely real}{0}{neither real nor imaginary}{a} \question The value of $i + i^{22} + i^{23} + i^{24} + i^{25}$ is \choice{i}{-i}{1}{-1}{c} \question The volume generated by rotating the triangle with vertices at (0, 0), (3, 0) and (3, 3) about x-axis is \choice{$18\pi$}{$2\pi$}{$36\pi$}{$9\pi$}{a} \question To complete the song, the last answer should be \choice{a}{b}{c}{d}{e} % Invalid answer choice \question To complete the song, the last answer should be \choice{a long tex a long tex a long tex a long tex a long tex a long tex a long tex a long tex a long tex}{b}{c}{d}{a} \end{questions} %\newpage %Uncomment to put on new age \bigskip Answer Key: \bigskip \showallanswers % Phil Hirschorn \end{document}

enter image description here

  • It seems exam class supports both [twocolumn], and \twocolumn[full width text]. See also tex.stackexchange.com/questions/326940/… Commented Nov 19, 2019 at 3:55
  • A little bit easier than the previous comment, have you tried to use \section*{Answer to Practice Exercises}, then adding a horizontal line with \hline or \rule, and the printing the question?
    – plr
    Commented Nov 19, 2019 at 9:57
  • @JohnKormylo I know but when i use this option on class the choices seems overlap the column. * I edit my main comment with the code.
    – miguel747
    Commented Nov 19, 2019 at 11:33
  • 1
    Thank u @plr for this suggestion. I will try to make section without number when i resolve the first problem.
    – miguel747
    Commented Nov 19, 2019 at 11:38

1 Answer 1


As stated in the comments, it seems that you want to do two things: create a two columns environment and then add the horizontal line in the answer section.

For creating two (or more columns), you can use the multicol package. A possible way of using it would be:

% more preamble


\begin{multicols}{3}  % the number here is the number of columns
[  % the part between square brackets isn't divided into columns
\section{First Section}
All human things are subject to decay. And when fate summons, Monarchs must 
]  % now the columns start
Hello, here is some text without a meaning.  This text should show what 
a printed text will look like at this place.
If you read this text, you will get no information.  Really?  Is there 
no information?  Is there...

% rest of the document

Using the previous code with the exam package options, you can create several columns with your code.

For creating the horizontal rule without the number in the name of the section, you can use the following code:

\section*{Answer to Practice Exercises}

Or you can use \rule if you have problems with interline spacing:

\section*{Answer to Practice Exercises}

This last part should be inside the \showallanswers (which, by the way, is a command from the exam package?)

  • have you ever test your solution with my code? I've tried to use multicols and doesnt fit well.
    – miguel747
    Commented Nov 20, 2019 at 19:29
  • @miguel747, you either wrongly copied your code or something's wrong with it. I tried to compile it and got so many errors. Try to debug the code by commenting out certain parts and see if some of the errors change or disappear. I see so many \newcommand defining new things that you might not fully understand. It's better to start from something more straightforward that you now and build from that.
    – plr
    Commented Nov 20, 2019 at 23:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .