2

I am writing an exam using \usepackage{exercise}. I have been using this package for some time with great results.

However, this time, I would like to insert a small image on the right side of the exercise's questions.

I've been trying several options, and finally settled for the minipage environment, since it is mentioned to work fine in the doc of the exercise package.

But I get the following unintended result

not really 2 columns here

If I replace the image with text, things work fine : I do get the 2 intended columns.

Here is a mwe

\documentclass{article}
\usepackage{exercise}
\usepackage{graphicx} 
\begin{document}
\begin{minipage}[t]{.7\textwidth} 
\begin{Exercise}[label=ex6, origin={1.5 points}]
\Question This is question 1.
\vspace{1cm}
\Question This is question 2.
\vspace{1cm}
\Question This is question 3.
\vspace{1cm}
\end{Exercise}
\end{minipage}
\begin{minipage}[t]{.3\textwidth} 
\centering 
\includegraphics[width=\textwidth]{dyn.jpg}
\end{minipage}
\end{document}

The \vspace is to allow some space for the student to write the answer.

3

1 Answer 1

1

The problem is that the base line of the included graphics is at the bottom side of the picture and not in the middle. This could by corrected by e.g. an adapted raisebox around the includegraphics.

Another option is to use tcolorbox with its sidebyside option:

\documentclass{article}
\usepackage{exercise}
\usepackage{graphicx}
\usepackage[many]{tcolorbox}
\begin{document}
\begin{tcolorbox}[blank,sidebyside,
  sidebyside gap=3mm,lefthand width=0.7\textwidth]
  \begin{Exercise}[label=ex6, origin={1.5 points}]
  \Question This is question 1.
  \vspace{1cm}
  \Question This is question 2.
  \vspace{1cm}
  \Question This is question 3.
  \vspace{1cm}
  \end{Exercise}
  \tcblower
  \includegraphics[width=\linewidth]{example-image-a}
\end{tcolorbox}
\end{document}

enter image description here

The lefthand width controls the width of the exercise text. sidebyside gap is the distance between the left and right side. Everything below \tcblower is on the right side (your picture). The \linewidth is the resulting width for the righthand side.

2
  • This could be a useful option. But it requires yet another package (tcolorbox). The simpler way here is to add \vspace{0pt} just before the image as mentioned in the above comment. One can also increase the value from 0pt to 20pt for example to adjust the image to a lower position.
    – macxpat
    Nov 14, 2013 at 19:43
  • As I wrote at the begin of my answer, the problem is the position of the base line of the graphics which becomes the reference line of the minipage. If you add \vspace{0pt} you add a new reference position for alignment before the picture is inserted. The linked and related questions and answers contain similar solutions and/or raiseboxes and/or positioning with TikZ. My answer uses TikZ under the cover to align the text and the picture box centered. But there are many possible solutions. Nov 15, 2013 at 7:32

You must log in to answer this question.

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