# Exam Class : With Question with images and border

I'm learning Exam Class to generate question paper. Sample tex code is mentioned below:

\documentclass{exam}
\usepackage{tikz}

\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,fill,inner sep=1.5pt, text=white] (char) {#1};}}
\renewcommand{\questionlabel}{\circled{\thequestion}}
\begin{document}
\begin{questions}
\question[4] Choose the correct reponse:
\begin{choices} \choice Option A
\choice Option B
\choice Option C
\choice Option D
\end{choices}
\end{questions}
\end{document}


Can you please give some direction to add questions [37 & Passage for 15-19] mentioned below:

-
mdframed for the boxes, wrapfig or some simple minipages should do get you started :) –  cmhughes Oct 17 '13 at 3:38
Also see \uplevel in the exam documentation. –  Sean Allred Oct 17 '13 at 4:22
Also, the example given isn't logically consistent, which will be more difficult to reproduce in LaTeX. Specifically, the entirety of question 37 is framed, whereas the others frame only a 'passage'. (This latter framing is most certainly a duplicate, and can be integrated into exam without any special treatment.) –  Sean Allred Oct 17 '13 at 20:33
I do this sort of thing a lot (see elfsoft2000.com/worksheets) but I do not use exam class, have no intention of ever using exam class, and do not want to read the manual. –  John Kormylo Oct 17 '13 at 22:03
The tricky part is not putting text into a rounded frame, but getting aligned with all the other questions. The easiest way to do this is to put every question or text into a minipage with the same width and center them on the page. Once again, this is not something you can do using exam class. –  John Kormylo Oct 18 '13 at 16:23
show 1 more comment

This is part of the solution. Obviously you would use your own clip art.

\documentclass[a4paper,addpoints,answers,10pt]{exam}
\usepackage{tikz}
\usepackage{graphicx}

\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,fill,inner sep=1.5pt, text=white] (char) {#1};}}
\renewcommand{\questionlabel}{\circled{\thequestion}}
\begin{document}
\begin{questions}
\question[4] Choose the correct reponse:
\begin{choices} \choice Option A
\choice Option B
\choice Option C
\choice Option D
\end{choices}

\hspace*{-0.27in}\begin{tikzpicture}[rounded corners=5pt]
\path node[rectangle,draw=black] {\hspace*{.23in}\parbox{5.97in}{
\question[4] Choose the correct reponse:
\begin{choices} \choice Option A
\choice Option B
\choice Option C
\choice Option D
\end{choices}
}};
\end{tikzpicture}

\hspace*{-0.27in}\begin{tikzpicture}[rounded corners=5pt]
\path node[rectangle,draw=black] {\begin{minipage}{6.2in}
\begin{minipage}[c]{5in}
\raggedright\setlength{\parskip}{0.1in}
There are many kinds of boats.

One kind of boat is called a sailboat.  It uses wind to move.
Wind makes the sailboat move in the water.
Wind pushes the sailboat.  Wind fills the sails.
The sailboat moves when the wind blows.
\end{minipage}\hfill\parbox[c]{1in}{\resizebox{1in}{!}{\includegraphics{sailboat.png}}}

\parbox[c]{1in}{\resizebox{1in}{!}{\includegraphics{motorboat.png}}}\hfill
\parbox[c]{5in}{\raggedright
One kind of boat is called a motorboat.
A motorboat uses a motor to move.
The motor gives power to the boat.
The motorboat moves when the motor is running,
The motor makes a loud noise.}

\parbox[c]{5in}{\raggedright
One kind of boat is called a rowboat.
A rowboat needs people to move it.
People make a rowboat move in the water.
People use oars to move a rowboat.
Oars are long and flat.
Oars go into the water.
A rowboat moves when people use the oars.
}\hfill\parbox[c]{1in}{\resizebox{1in}{!}{\includegraphics{rowboat.png}}}
\end{minipage}
};
\end{tikzpicture}

\end{questions}
\end{document}


-
The problem with fitting the question inside the frame is that the question number is outside the margins. –  John Kormylo Oct 22 '13 at 5:01
Thanks John for providing above solution. –  Pawan Mude Oct 25 '13 at 10:56

Here is a try with tcolorbox.

\documentclass{exam}
\usepackage{tcolorbox}
\usepackage{showframe,lipsum}
%
\tcbuselibrary{skins}
\usetikzlibrary{calc}
\pgfdeclarelayer{foreground}
\pgfsetlayers{main,foreground}
%
\newtcolorbox{myqbox}{%
colback=white,
left=-1ex, % left space between content text and box I don't know why -1ex is needed here
top=0pt,
bottom=0pt,
right=0pt,
skin=freelance,
enlarge left by=0pt,
frame code={%
\begin{pgfonlayer}{foreground}
\draw[line width = 2pt,color = magenta,rounded corners=2ex] ($(frame.south west) +(-1.2\leftmargin,-.2em)$) rectangle ($(frame.north east)+(.3em,.2em)$);
\end{pgfonlayer}%
},
}%
%
\newtcolorbox{mybox}{%
colback=white,
left=0ex, % left space between content text and box I don't know why -1ex is needed here
top=0pt,
bottom=0pt,
right=0pt,
arc=2ex,
oversize
}%
%

\newcommand*\circled[1]{\tikz[baseline=(char.base)]{%
\node[shape=circle,fill,inner sep=1.5pt, text=white] (char) {#1};}}
\renewcommand{\questionlabel}{\circled{\thequestion}}
\begin{document}
\begin{questions}
\question[4] Choose the correct reponse:
\begin{choices} \choice Option A
\choice Option B
\choice Option C
\choice Option D
\end{choices}
%
\begin{myqbox}%
\question[4] Choose the correct reponse just to fill the line of text until the end of line for having some fun and test:
\begin{choices} \choice Option A
\choice Option B
\choice Option C
\choice Option D
\end{choices}
\end{myqbox}
%
\uplevel{%
{\bfseries Read the following and go to heaven}
\begin{mybox}
\lipsum[1]
\end{mybox}
}
%
\begin{myqbox}%
\question[4] Choose the correct reponse just to fill the line of text until the end of line for having some fun and test:
\begin{choices} \choice Option A
\choice Option B
\choice Option C
\choice Option D
\end{choices}
\end{myqbox}
\end{questions}
\end{document}


Caveats: If you want to add background color for questions, then you are in trouble. Also I don't understand why I have to add left=-1ex,.

-
Rounded corners need larger margins so that the text doesn't overlap the corner (hence the -1ex). –  John Kormylo Oct 22 '13 at 0:39
@JohnKormylo I am afraid, it is not so. –  Harish Kumar Oct 22 '13 at 0:41
Yeah, I noticed that it wasn't needed for the \mybox. Perhaps it is due to the line width. –  John Kormylo Oct 22 '13 at 0:51
Thanks Harish for providing option mentioned above. –  Pawan Mude Oct 25 '13 at 10:57

Considering how complex the above are, is the following all that difficult?

\documentclass{article}
\usepackage[margin=1in]{geometry}

\setlength{\parindent}{0in}
\setlength{\parskip}{0.1in}

\newlength{\qwidth}
\setlength{\qwidth}{\textwidth}

\newcommand{\qbox}{\framebox[0.25in]{\rule{0in}{.2in}} \hspace*{0.1in}}

\newcommand{\question}[2]%#1 = problem number, #2 = statement
{(#1) \qbox
\parbox[t]{\qwidth}{\raggedright #2}
\par\vfill}

\newcommand{\qmult}[3]%#1 = number, #2 = question, #3 = choices
{(#1) \qbox \parbox[t]{\qwidth}{\raggedright #2}\par
\hspace*{0.1in}
\begin{tabular}{ll}#3\end{tabular}\\
\vfill}

\newcommand{\qchoice}[2]%#1 = letter, #2 = text
{#1.&#2\\}

\begin{document}
\pagestyle{empty}
\large
\framebox[3in][l]{\rule{0in}{0.25in}\tiny name}\hfill
\framebox[1.5in][l]{\rule{0in}{0.25in}\tiny date}\hfill
\framebox[0.4in][l]{\rule{0in}{0.25in}\tiny period}

\begin{center}
{\huge Attitude}
\end{center}
\rule{\textwidth}{1pt}

Answer true (T) or false (F).
\par\vfill
\question{1}{I'm not going to learn anything, and you can't make me.}
\question{2}{If it's not about sports, video games, pop culture, me or
my friends, I don't want to hear about it.}
\question{3}{If it's not going to be on the test, I don't need to know it.}
\question{4}{When I try to do math all I can think of is I hate this!
I hate this!  I hate this!''}
\question{5}{No one I know or admire is any good at math either.}
\question{6}{I enjoy solving puzzles.}
\rule{\textwidth}{1pt}

Multiple choice.

\qmult{7}{I won't need an education if I am going to be  \underline{\rule{0.5in}{0pt}} .}{
\qchoice{B}{a convicted felon}
\qchoice{C}{in a permanent drunken stupor}
\qchoice{D}{on an MTV reality show}
}
\qmult{8}{Given a choice, I would rather be \underline{\rule{0.5in}{0pt}} .}{
\qchoice{A}{ignorant}
\qchoice{B}{narrow minded}
\qchoice{C}{self-destructive}
\qchoice{D}{unpopular}
}

\end{document}


BTW, I know how to use counters, I just don't like them.

-