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:
and when I use \showallanswers
we print this header
Any suggestion?
\documentclass[11pt,a4paper,twocolumn]{exam} \usepackage{amsmath,amsthm,amsfonts,amssymb,dsfont} \usepackage{ifthen} \usepackage{multicol}% 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}
\begin{document}
\Large
\noindent{\bf Ma 12 Long Test 1\hfill 9 February 2017}
\medskip\hrule
\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}