8

MWE

\documentclass[11pt,a4paper]{exam}
%\documentclass[11pt,a4paper,answers]{exam}

\usepackage{multicol}

\begin{document}
\begin{multicols}{2}
\begin{questions}

\question FIRST QUESTION

\begin{oneparchoices}
\choice ABC
\choice DEF
\CorrectChoice GHI
\choice JKL
\choice MNO
\end{oneparchoices}

\question SECOND QUESTION

\begin{oneparchoices}
\choice ABCDEF
\choice GHIJKL
\CorrectChoice GHI
\choice JKL
\choice MNO
\end{oneparchoices}

\end{questions}

\vfill
\columnbreak

EXAM FINISH

\end{multicols}
\end{document}

That I want centering in last line E answer or D and E answers. Is it possible?

enter image description here

...@JasperHabicht Solution...

When options are short, something like this happens... enter image description here

Can it be left-aligned (in original package) or distribute text?

4
  • Sorry, I currently cannot think of a feasible solution of this second problem. You would have to test the length of the questions block in order to check if it is more than one line. If yes keep it left-aligned, if not set it to justify-centering. But I can't think of an easy way to do this. Also, the exam package seems to be a bit unstable which makes it even more difficult to come up with possible solutions. Maybe you really stick to the old environment and use another one with the code I proposed for the longer questions. Maybe someone else comes up with a better solution. :/ Sep 6, 2017 at 4:58
  • @JasperHabicht, you're welcome. So far, your help and the information you wrote made me happy. I expect you to be interested in my other questions.
    – Özgür
    Sep 6, 2017 at 5:09
  • you are lucky. I just found a possible solution which I added to my answer below. Sep 6, 2017 at 5:16
  • @JasperHabicht, Yes I am lucky indeed. [Solved]
    – Özgür
    Sep 6, 2017 at 5:24

1 Answer 1

10
+50

One solution would be to use this approach to center the last line in the paragraph while leaving the rest justified. So, you could define a new environment in your document preamble and use it instead of the old one, like this:

\newenvironment{oneparchoicescentering}{
 \begingroup
 \leftskip=0mm plus .5fil%
 \rightskip=0mm plus -.5fil%
 \parfillskip=0mm plus 1fil\relax
 \begin{oneparchoices}
}{
 \end{oneparchoices}
 \par
 \endgroup
}

The \par is needed in order to make the paragraph complete in a way. I tried without, but this doesn’t seem to work. I guess, it is needed to change from horizontal mode back into vertical in order to place the boxes properly.

The result would be:

enter image description here

Is this want you want to achieve?

By the way, you should use a4paper instead of paper=a4 as option in your document class. Also, I think that using only capital letters makes the text a bit hard to read ...


Edit: If you want to overwrite the oneparchoices environment in order to be able to keep the syntax, you could instead put the following in your preamble (the following at the same time being a MWE):

\documentclass[11pt,a4paper]{exam}
\usepackage{multicol}

\let\oldoneparchoices\oneparchoices
\let\oldendoneparchoices\endoneparchoices
\renewenvironment{oneparchoices}{
 \begingroup
 \leftskip=0mm plus .5fil%
 \rightskip=0mm plus -.5fil%
 \parfillskip=0mm plus 1fil\relax
 \begingroup\oldoneparchoices
}{
 \oldendoneparchoices\endgroup
 \par
 \endgroup
}

\begin{document}

\begin{multicols*}{2}
\begin{questions}

\question First Question

\begin{oneparchoices}
 \choice ABC
 \choice DEF
 \CorrectChoice GHI
 \choice JKL
 \choice MNO
\end{oneparchoices}

\end{questions}
\end{multicols*}

\end{document}

Single-line answers not centered

In order to prevent single-line answers to be also centered (although I personally would not mix centered and ragged right text), the following code could be used making use of the package environ:

\documentclass[11pt,a4paper]{exam}
\usepackage{multicol}

\let\oldoneparchoices\oneparchoices
\let\oldendoneparchoices\endoneparchoices
\let\oneparchoices\relax         % We have to unset these to make \NewEnviron work
\let\endoneparchoices\relax
\usepackage{environ}             % Load environ package 
\newlength{\choiceslen}          % Creating new length for later test
\NewEnviron{oneparchoices}{
 \begingroup
 \settowidth{\choiceslen}{%      % Setting the above created length to the length of all answers
  \begingroup\oldoneparchoices
  \BODY
  \oldendoneparchoices\endgroup%
 }
 \ifdim\choiceslen>\linewidth    % Test if length exceeds one line, if yes center last line
  \leftskip=0mm plus .5fil%
  \rightskip=0mm plus -.5fil%
  \parfillskip=0mm plus 1fil\relax
 \fi 
 \begingroup\oldoneparchoices
 \BODY
 \oldendoneparchoices\endgroup
 \par
 \endgroup
}

\begin{document}

\begin{multicols*}{2}
\begin{questions}

\question First Question

\begin{oneparchoices}
 \choice ABC
 \choice DEF
 \CorrectChoice GHI
 \choice JKL
 \choice MNO
\end{oneparchoices}

\question Second Question

\begin{oneparchoices}
 \choice ABC
 \choice DEF
 \CorrectChoice GHI
\end{oneparchoices}

\end{questions}
\end{multicols*}

\end{document}

I hope this works as it should. Result would be:

enter image description here

11
  • Your suggestions are important to me. I will check your code.
    – Özgür
    Aug 31, 2017 at 19:46
  • 1
    pls add an MWE to your answer :)
    – JulianWgs
    Sep 1, 2017 at 11:19
  • 1
    @Julian_W: MWE added. I used the multicols* environment here only to show the desired effect. The code should also work in a single-column environment or with the unstarred version of the environment. Sep 1, 2017 at 12:04
  • @JasperHabicht, please edited my question.
    – Özgür
    Sep 5, 2017 at 17:02
  • 1
    @Özgür: You should replace \begingroup\oldoneparchoices in line 13 (but not in line 22!) with \begingroup\renewcommand{\Cchoice}{\CorrectChoice}\oldoneparchoices. The reason why everything is counted twice is, that I told LaTeX to typeset the answers internally first in order to know whether they are too long for one line. So, \Cchoice and hence the answer counter is also called twice. With the above code, \Cchoice is reset to do only the formatting, but to not increase the answer counter, when LaTeX typesets internally. Upon real typesetting, \Cchoice will still call the counter. Jan 21, 2018 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.