Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The following code produces an output that has badly-spaced contents. My objective is to write an exercise with multiple choice questions. Each option may have a figure.

enter image description here

The red arrows indicate the badly-spaced parts.

\documentclass[demo]{article}
\usepackage[a4paper,margin=20mm]{geometry}
\usepackage{graphicx}
\usepackage{multicol}
\columnsep=10pt
\usepackage{enumerate}

\def\question{%
Which is the correct statement about a quadratic function?}

\def\option{%
When $D<0$, the graph has 2 $x$-intercepts as shown in the figure below.

\begin{center}
        \includegraphics[width=0.8\linewidth]{foo}
\end{center}}%

\begin{document}
\begin{multicols}{2}[\section*{Exercise}]
\begin{enumerate}[1.]
% Question 1
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols} 
% Question 2
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols}
% Question 3
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols} 
% Question 4
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols}
\end{enumerate}
\end{multicols}
\end{document}

How to get a better spacing in nested multicols environments? I also noticed the spacing gets weird in both text mode and math mode.

If this problem is not easy to fix, is there another way to accomplish my objective, i.e., creating a multiple-choice exercise with the same layout as shown above?

share|improve this question
    
Can you please explain the terms "The current answers do not contain enough detail" and "I am looking for a better solution"? What sort of additional detail are you looking for? and in what respect do you expect a solution to be better? –  Yiannis Lazarides Feb 18 '12 at 6:57
    
You need to be more specific, the layout you illustrated above shows a four column text with the image below the option, whereas the comments you have been making on both my answer and the accepted answer was pointing that maybe you want wrapped images. As I also said on my last comment, you need to post somewhere say at pastebin, actual text and images. Layouts react differently to sizing that varies and sometimes is not always possible to achieve good balance between the columns. . –  Yiannis Lazarides Feb 18 '12 at 7:48
    
Where did you see that my solution needs reconfiguring. What I have been asking you was to post real questions and answers for testing the code and I see no reason why you ducking the request. Anyway this was my 2cents. –  Yiannis Lazarides Feb 18 '12 at 8:08
add comment

3 Answers

up vote 9 down vote accepted
+750

How do you like this? May be it could be an approach for you. It was done with the picins-package.

enter image description here

enter image description here

\documentclass[demo]{article}
\usepackage[a4paper,margin=20mm]{geometry}
\usepackage{graphicx}
\usepackage{multicol}
\columnsep=10pt
\usepackage{enumerate}
\usepackage{picins}

\def\question{%
Which is the correct statement about a quadratic function?}

\def\option{%
When $D<0$, the graph has 2 $x$-intercepts as shown in the figure below.\picskip{0}%
}

\def\fig{%
\parpic(3cm,3cm)[rd]{\includegraphics[height=2cm,width=2cm]{foo}}%
}%

\begin{document}
\begin{multicols}{2}[\section*{Exercise}]
\begin{enumerate}[1.]
% Question 1
\item \question
\begin{enumerate}
 \item\fig\option
 \item\fig\option
 \item\fig\option
 \item\fig\option
\end{enumerate}
\item \question
\begin{enumerate}
 \item\fig\option
 \item\fig\option
 \item\fig\option
 \item\fig\option
\end{enumerate}
\item \question
\begin{enumerate}
 \item\fig\option
 \item\fig\option
 \item\fig\option
 \item\fig\option
 \item\fig\option
\end{enumerate}
\item \question
\begin{enumerate}
 \item\fig\option
 \item\fig\option
 \item\fig\option
 \item\fig\option
 \item\fig\option
\end{enumerate}
\end{enumerate}
\end{multicols}
\end{document}
share|improve this answer
    
Please give us more details about your requirements. Maybe we can provide other examples which fits your needs. –  Holle Feb 16 '12 at 9:29
1  
@ Counter Terrorist: Did you tried my example? The text is floating around the figure. I inserted an second picture where you can see it. Is it what you want? –  Holle Feb 16 '12 at 16:49
add comment

The nesting of enumeration environments and multicolumn layouts is always problematic. Besides the code becomes messy quickly and will be difficult to use. The user commands should be able to run as:

\begin{...}[]
\question{}
\option{}
\option{}

\question{}
\option{}
\option{}
\end{...} 

And give you this:

enter image description here

Here is the MWE code:

\documentclass[demo]{article}
\usepackage[a4paper,margin=20mm]{geometry}
\usepackage{graphicx,xcolor}
\usepackage{multicol}
\columnsep=1.5em
\usepackage{pgfplots}
% better try a real example
\def\demoplot{%
\pgfplotsset{width=120pt,compat=1.3}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2 - x +4};
\end{axis}
\end{tikzpicture}
}
\parindent0pt
\makeatletter
% some counters 
\newcounter{ctr}\setcounter{ctr}{0}
\newcounter{ctrr}[ctr]\setcounter{ctrr}{0}
% to step counters and add some style
\def\inc{%
  \stepcounter{ctr}
  \bfseries\sffamily
  \color{blue}\thectr.
}
\def\Inc{%
  \stepcounter{ctrr}
  \color{purple}
  \bfseries\sffamily
  \alph{ctrr}.
}
% question 
\newcommand\question[1]{%
  \leavevmode
  \@hangfrom{\hbox to 15pt{\inc \hfill}}{%
     #1\par}%
}
% demo question
\newcommand{\demoquestion}{%
 \question{Which is the correct statement about 
      a quadratic function?}
}
% option
\newcommand\option[2]{%
  \vbox{\begin{minipage}{0.45\linewidth}
    \@hangfrom{\hbox to 15pt{\Inc}}{#1}
  \end{minipage}\hskip10pt\begin{minipage}{0.45\linewidth}
     \vspace*{5.5pt}%
     \centering%
     #2%\rule{80pt}{80pt}%#2
     \vspace{5.5pt}
  \end{minipage}\par}
}%
% option for demo
\newcommand{\demooption}{%
  \option{When $D<0$, the graph has 2 $x$- 
         intercepts as shown in the figure 
         below.}{\demoplot}
}
\makeatother

\begin{document}
\begin{multicols}{2}[\section*{\textcolor{purple}{EXERCISE}}]
    \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption

   \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption

    \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption


    \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption

\end{multicols}
\end{document}

An alternative plan as per comments:

enter image description here

and a new MWE:

\documentclass[demo]{article}
\usepackage[a4paper,margin=20mm]{geometry}
\usepackage{graphicx,xcolor}
\usepackage{multicol}
\columnsep=1.5em
\usepackage{pgfplots}
\usepackage{enumerate}
\def\demoplot{%
\pgfplotsset{width=110pt,compat=1.3}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2 - x +4};
\end{axis}
\end{tikzpicture}
}
\parindent0pt
\makeatletter
\newcounter{ctr}\setcounter{ctr}{0}
\newcounter{ctrr}[ctr]\setcounter{ctrr}{0}

\def\inc{%
  \stepcounter{ctr}
  \bfseries\sffamily
  \color{blue}\thectr.
}
\def\Inc{%
  \stepcounter{ctrr}
  \color{purple}
  \bfseries\sffamily
  \alph{ctrr}.
}
% Demo question
\newcommand\question[1]{%
  \leavevmode
  \@hangfrom{\hbox to 15pt{\inc \hfill}}{%
     #1\par}%
}

\newcommand{\demoquestion}{%
 \question{Which is the correct statement about 
      a quadratic function?}
 \medskip
}
% Demo answer
\newcommand\option[2]{%
  \vbox{\hbox to \linewidth{\begin{minipage}[b]{0.45\linewidth}
    \@hangfrom{\hbox to 15pt{\Inc}}{#1}
    \end{minipage}\hfill%\hskip0.05\textwidth
    \begin{minipage}{0.45\linewidth}
     \vspace{-6pt} 
     \centering%
     \fbox{#2}%\rule{80pt}{80pt}%#2
  \end{minipage}\par}}
\smallskip
}%


\newcommand{\demooption}{%
  \option{When $D<0$, the graph has 2 $x$- 
         intercepts as shown in the figure 
         below.}{\demoplot}
}
\makeatother
\begin{document}
\begin{multicols}{2}[\section*{\textcolor{purple}{EXERCISE}}]
    \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption

   \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption

    \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption


    \demoquestion
    \demooption
    \demooption
    \demooption
    \demooption

\end{multicols}
\end{document}

Add on code for wrapped figures.

We use the wrapfig package to wrap text to figures and still avoid lists. So what we do we build up the indentation and counters. The result looks like:

enter image description here

And the final MWE example:

\documentclass[demo]{article}
\usepackage[a4paper,margin=20mm]{geometry}
\usepackage{graphicx,xcolor}
\usepackage{multicol}
\columnsep=1.5em
\usepackage{pgfplots}
\usepackage{wrapfig}
\usepackage{ragged2e}
% better try a real example
\def\demoplot{%
\pgfplotsset{width=120pt,compat=1.3}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2 - x +4};
\end{axis}
\end{tikzpicture}
}
\parindent0pt
\makeatletter
% some counters 
\newcounter{ctr}\setcounter{ctr}{0}
\newcounter{ctrr}[ctr]\setcounter{ctrr}{0}
% to step counters and add some style
\def\inc{%
  \stepcounter{ctr}
  \bfseries\sffamily
  \color{blue}\thectr.
}
\def\Inc{%
  \stepcounter{ctrr}
  \color{purple}
  \bfseries\sffamily
  \alph{ctrr}.
}
% question 
\newcommand\question[1]{%
  \leavevmode
  \@hangfrom{\hbox to 15pt{\inc \hfill}}{%
     #1\par}%
}
% demo question
\newcommand{\demoquestion}{%
 \question{Which is the correct statement about 
      a quadratic function?}
}
% option
\newcommand\option[2]{%
  \vbox{\begin{minipage}{0.45\linewidth}
    \@hangfrom{\hbox to 15pt{\Inc}}{#1}
  \end{minipage}\hskip10pt\begin{minipage}{0.45\linewidth}
     \vspace*{5.5pt}%
     \centering%
     #2%\rule{80pt}{80pt}%#2
     \vspace{5.5pt}
  \end{minipage}\par}
}%
% option for demo
\newcommand{\demooption}{%
  \option{When $D<0$, the graph has 2 $x$- 
         intercepts as shown in the figure 
         below.}{\demoplot}
}

\newcommand\WrapFigure[1]{%
\begin{minipage}{0.9\linewidth}
\vspace{0pt} 
\setlength\intextsep{0pt}%
\setlength{\columnsep}{0pt}
\begin{wrapfigure}{r}[-10pt]{100pt}%
\demoplot %the image
\end{wrapfigure}
\hskip-20pt\@hangfrom{\hbox to 15pt{\Inc}}
\leftskip15pt
#1\par 
\end{minipage}
\vspace{\baselineskip}
}
\begin{document}
\begin{multicols*}{2}[\section*{\textcolor{purple}{EXERCISE}}]
\WrapFigure{%
This is a test of some sort to check it out. 
To see what is happening here. This is a test of some sort to check it out. To see what is happening here.\par
This is a test of some sort to check it out. 
To see what is happening here. This is a test of some sort to check it out. To see what is happening here.}
\medskip
\leftskip0pt
\demooption
\end{multicols*}
\end{document}
share|improve this answer
    
You example looks good. But how can you align the text so that the text and the picture starts on the same height? It seams that the text is aligned to the bottom of the picture. If there is little text and a huge picture it looks strange. And how can you right-align the pictures to the question text? –  Holle Feb 12 '12 at 11:33
    
@Holle First the right-align (replace \hskip10pt with \hfill and will align. You might think it is not due to the space around the TikZ figure. Just replace #2 with \fbox{#2} in the \option definition and you will see what I mean. Will modify as per your suggestions a bit later and recapture a new image. –  Yiannis Lazarides Feb 12 '12 at 12:27
1  
@CounterTerrorist I wouldn't recommend that it does. It is bad typography for this type of text. I would post some code tomorrow for it as a separate command, then you can used both. –  Yiannis Lazarides Feb 13 '12 at 15:23
    
@CounterTerrorist Please see revisions. –  Yiannis Lazarides Feb 16 '12 at 10:30
    
@CounterTerrorist If you post somewhere 2 real questions and 5 actual options, I will give it a try. I am no too kin to test a layout only on sample data. I mean otherwise it is easy to wrap commands in a macro to test. –  Yiannis Lazarides Feb 16 '12 at 15:50
show 4 more comments

If you replace the center environment with \centering and use raggedcolumns you get better results:

enter image description here

\documentclass[demo]{article}
\usepackage[a4paper,margin=20mm]{geometry}
\usepackage{graphicx}
\usepackage{multicol}
\columnsep=10pt
\usepackage{enumerate}

\def\question{%
Which is the correct statement about a quadratic function?}

\def\option{%
When $D<0$, the graph has 2 $x$-intercepts as shown in the figure below.

\centering
        \includegraphics[width=0.8\linewidth]{foo}
}%

\begin{document}
\begin{multicols}{2}[\section*{Exercise}]\raggedcolumns
\begin{enumerate}[1.]
% Question 1
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols} 
% Question 2
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols}
% Question 3
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols} 
% Question 4
\item \question
    \begin{multicols}{2}
    \begin{enumerate}[a.]
        \item \option
        \item \option
        \item \option
        \item \option
        \item \option   
    \end{enumerate}
    \end{multicols}
\end{enumerate}
\end{multicols}
\end{document}
share|improve this answer
    
On "normal" paper (i.e, \usepackage{geometry}) it does not look so bad. I suspect with the different paper size the problem has something to do with column balancing, but don't know how to help you further. –  Peter Grill Feb 8 '12 at 21:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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