1

I need to create an exam with a complex structure (using parts, subparts and occasionally even subsubparts). At the same time I have only a limited number of pages available and thus need to place graphics next to text to reduce empty whitespace.

What works pretty well is putting a single item (part, or subpart, or subsubpart) next to a graphic using paracol. But sometimes a single item has much less vertical space than a graphic. So I'd need to put several items, possibly of different type, in one column, and a graphic into another column.

I think, I have found a way to pause any type of list at the end of a paracol environment and then resume it with the correct numbering as described at How can I resume the part numbering in exam document class?

But now my problem is that the text in the left column doesn't actually stay in the left column but rather spills into the right column and overlaps the graphics there. Only the very first item in the paracol environment actually follows the column width. Here's an example (not minimal but demonstrates the kind of nested items structure, the problem already happens in the first subpart):

\documentclass[a4paper,
draft,
12pt]{exam}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[pangram]{blindtext}
\usepackage{graphicx}
\usepackage{paracol}

\pointformat{/\thepoints}
\addpoints
\pointsdroppedatright 



%%%Exercises numbering%%%
%%% https://tex.stackexchange.com/questions/682327/exam-class-define-questionlabel-and-partlabel-conditionally/682446#682446 %%%
\makeatletter
\renewcommand{\thequestion}{\arabic{question}\@ifundefined{r@part@\arabic{question}@1}{\phantom{.0}}{.0}}
\renewcommand{\thepartno}{\arabic{question}.\arabic{partno}\@ifundefined{r@subpart@\arabic{question}@\arabic{partno}@1}{\phantom{.0}}{.0}}
\renewcommand{\thesubpart}{\arabic{question}.\arabic{partno}.\arabic{subpart}\@ifundefined{r@subsubpart@\arabic{question}@\arabic{partno}@\arabic{subpart}@1}{\phantom{.0}}{.0}}
\renewcommand{\thesubsubpart}{\arabic{question}.\arabic{partno}.\arabic{subpart}.\arabic{subsubpart}}
\renewcommand{\questionlabel}{\thequestion\hfill}
\renewcommand{\partlabel}{\hbox to \labelwidth{\thepartno\hfill}}
\renewcommand{\subpartlabel}{\hbox to \labelwidth{\thesubpart\hfill}}
\renewcommand{\subsubpartlabel}{\hbox to \labelwidth{\thesubsubpart\hfill}}
\renewcommand{\questionshook}{
    \setlength{\leftmargin}{3em}
    \labelwidth\leftmargin\advance\labelwidth-\labelsep
    \setlength{\linewidth}{\textwidth}
}
\renewcommand{\partshook}{
    \setlength{\@totalleftmargin}{0pt}
    \setlength{\leftmargin}{3em}
    \labelwidth\leftmargin\advance\labelwidth-\labelsep
    \setlength{\linewidth}{\textwidth}
}
\renewcommand{\subpartshook}{
    \setlength{\@totalleftmargin}{0pt}
    \setlength{\leftmargin}{3em}
    \labelwidth\leftmargin\advance\labelwidth-\labelsep
    \setlength{\linewidth}{\textwidth}
}
\renewcommand{\subsubpartshook}{
    \setlength{\@totalleftmargin}{0pt}
    \setlength{\leftmargin}{3em}
    \labelwidth\leftmargin\advance\labelwidth-\labelsep
    \setlength{\linewidth}{\textwidth}
}
\makeatother

\newcounter{partscounter}
\newcounter{subpartscounter}
\newcounter{subsubpartscounter}

\begin{document}
    \begin{questions}
        \columnratio{0.6,0.4}
        \begin{paracol}{2}
            \begin{leftcolumn}
                \question \Blindtext[1][3]
                \begin{parts}
                    \part \Blindtext[1][3]
                    \begin{subparts}
                        \subpart[1] \Blindtext[1][3]
                        
                        \droppoints
                        
                        \subpart[1] \Blindtext[1][3]
                        \setcounter{subpartscounter}{\value{subpart}}
                    \end{subparts}
                    \setcounter{partscounter}{\value{partno}}
                \end{parts}
            \end{leftcolumn}
            \begin{rightcolumn}
                \includegraphics[width=\linewidth]{graphic.png}
            \end{rightcolumn}
        \end{paracol}
        \begin{subparts}
            \setcounter{subpart}{\value{subpartscounter}}
            \subpart \Blindtext[1][3]
            \begin{subsubparts}
                \subsubpart[1] \Blindtext[1][3]
                
                \subsubpart[1] \Blindtext[1][3]
                
                \subsubpart[1] \Blindtext[1][3]
            \end{subsubparts}
        \end{subparts}
        \begin{parts}
            \setcounter{partno}{\value{partscounter}}
            \part[1] \Blindtext[1][3]
        \end{parts}
    \end{questions}
\end{document}

Here is how it looks like:

Text going into the right column and overlapping with the graphic

Here is a variant with a minipage in the left column:

\documentclass[a4paper,
draft,
12pt]{exam}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[pangram]{blindtext}
\usepackage{graphicx}
\usepackage{paracol}

\pointformat{/\thepoints}
\addpoints
\pointsdroppedatright 



%%%Exercises numbering%%%
%%% https://tex.stackexchange.com/questions/682327/exam-class-define-questionlabel-and-partlabel-conditionally/682446#682446 %%%
\makeatletter
\renewcommand{\thequestion}{\arabic{question}\@ifundefined{r@part@\arabic{question}@1}{\phantom{.0}}{.0}}
\renewcommand{\thepartno}{\arabic{question}.\arabic{partno}\@ifundefined{r@subpart@\arabic{question}@\arabic{partno}@1}{\phantom{.0}}{.0}}
\renewcommand{\thesubpart}{\arabic{question}.\arabic{partno}.\arabic{subpart}\@ifundefined{r@subsubpart@\arabic{question}@\arabic{partno}@\arabic{subpart}@1}{\phantom{.0}}{.0}}
\renewcommand{\thesubsubpart}{\arabic{question}.\arabic{partno}.\arabic{subpart}.\arabic{subsubpart}}
\renewcommand{\questionlabel}{\thequestion\hfill}
\renewcommand{\partlabel}{\hbox to \labelwidth{\thepartno\hfill}}
\renewcommand{\subpartlabel}{\hbox to \labelwidth{\thesubpart\hfill}}
\renewcommand{\subsubpartlabel}{\hbox to \labelwidth{\thesubsubpart\hfill}}
\renewcommand{\questionshook}{
    \setlength{\leftmargin}{3em}
    \labelwidth\leftmargin\advance\labelwidth-\labelsep
    \setlength{\linewidth}{\textwidth}
}
\renewcommand{\partshook}{
    \setlength{\@totalleftmargin}{0pt}
    \setlength{\leftmargin}{3em}
    \labelwidth\leftmargin\advance\labelwidth-\labelsep
    \setlength{\linewidth}{\textwidth}
}
\renewcommand{\subpartshook}{
    \setlength{\@totalleftmargin}{0pt}
    \setlength{\leftmargin}{3em}
    \labelwidth\leftmargin\advance\labelwidth-\labelsep
    \setlength{\linewidth}{\textwidth}
}
\renewcommand{\subsubpartshook}{
    \setlength{\@totalleftmargin}{0pt}
    \setlength{\leftmargin}{3em}
    \labelwidth\leftmargin\advance\labelwidth-\labelsep
    \setlength{\linewidth}{\textwidth}
}
\makeatother

\newcounter{partscounter}
\newcounter{subpartscounter}
\newcounter{subsubpartscounter}

\begin{document}
    \begin{questions}
        \columnratio{0.6,0.4}
        \begin{paracol}{2}
            \begin{leftcolumn}
            \begin{minipage}[c]{\linewidth}
                \question \Blindtext[1][3]
                \begin{parts}
                    \part \Blindtext[1][3]
                    \begin{subparts}
                        \subpart[1] \Blindtext[1][3]
                        
                        \droppoints
                        
                        \subpart[1] \Blindtext[1][3]
                        \setcounter{subpartscounter}{\value{subpart}}
                    \end{subparts}
                    \setcounter{partscounter}{\value{partno}}
                \end{parts}
            \end{minipage}
            \end{leftcolumn}
            \begin{rightcolumn}
                \includegraphics[width=\linewidth]{graphic.png}
            \end{rightcolumn}
        \end{paracol}
        \begin{subparts}
            \setcounter{subpart}{\value{subpartscounter}}
            \subpart \Blindtext[1][3]
            \begin{subsubparts}
                \subsubpart[1] \Blindtext[1][3]
                
                \subsubpart[1] \Blindtext[1][3]
                
                \subsubpart[1] \Blindtext[1][3]
            \end{subsubparts}
        \end{subparts}
        \begin{parts}
            \setcounter{partno}{\value{partscounter}}
            \part[1] \Blindtext[1][3]
        \end{parts}
    \end{questions}
\end{document}

And here is how it looks like:

Variant with minipage environment

2
  • When I need to place text and graphics next to each other in exam class, I use minipage environment. When I want to resume the list after it, I just add \setcounter{partno}{} to the last previous item.
    – Piroooh
    Commented Oct 14, 2023 at 14:54
  • I tried that, unfortunately it leads to a horizontal shift. I will add this code variant and a screenshot demonstrating the problem.
    – Photon
    Commented Oct 14, 2023 at 15:11

2 Answers 2

1

First, 3em is not wide enough, expecially since it includes \labelsep. Second, you should set \linewidth to \columnwidth, not \textwidth. Finally, narrow columns hyphenate better with \sloppy than \fussy (default).

\documentclass[a4paper,
draft,
12pt]{exam}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[pangram]{blindtext}
\usepackage{graphicx}
\usepackage{paracol}

\pointformat{/\thepoints}
\addpoints
\pointsdroppedatright 



%%%Exercises numbering%%%
%%% https://tex.stackexchange.com/questions/682327/exam-class-define-questionlabel-and-partlabel-conditionally/682446#682446 %%%
\makeatletter
\renewcommand{\thequestion}{\arabic{question}\@ifundefined{r@part@\arabic{question}@1}{\phantom{.0}}{.0}}
\renewcommand{\thepartno}{\arabic{question}.\arabic{partno}\@ifundefined{r@subpart@\arabic{question}@\arabic{partno}@1}{\phantom{.0}}{.0}}
\renewcommand{\thesubpart}{\arabic{question}.\arabic{partno}.\arabic{subpart}\@ifundefined{r@subsubpart@\arabic{question}@\arabic{partno}@\arabic{subpart}@1}{\phantom{.0}}{.0}}
\renewcommand{\thesubsubpart}{\arabic{question}.\arabic{partno}.\arabic{subpart}.\arabic{subsubpart}}
\renewcommand{\questionlabel}{\thequestion\hfill}
\renewcommand{\partlabel}{\hbox to \labelwidth{\thepartno\hfill}}
\renewcommand{\subpartlabel}{\hbox to \labelwidth{\thesubpart\hfill}}
\renewcommand{\subsubpartlabel}{\hbox to \labelwidth{\thesubsubpart\hfill}}
\renewcommand{\questionshook}{%
    \setlength{\leftmargin}{4em}%
    \labelwidth\leftmargin\advance\labelwidth-\labelsep
    \setlength{\linewidth}{\columnwidth}%
}
\renewcommand{\partshook}{%
    \setlength{\@totalleftmargin}{0pt}%
    \setlength{\leftmargin}{4em}%
    \labelwidth\leftmargin\advance\labelwidth-\labelsep
    \setlength{\linewidth}{\columnwidth}%
}
\renewcommand{\subpartshook}{%
    \setlength{\@totalleftmargin}{0pt}%
    \setlength{\leftmargin}{4em}%
    \labelwidth\leftmargin\advance\labelwidth-\labelsep
    \setlength{\linewidth}{\columnwidth}%
}
\renewcommand{\subsubpartshook}{%
    \setlength{\@totalleftmargin}{0pt}%
    \setlength{\leftmargin}{4em}%
    \labelwidth\leftmargin\advance\labelwidth-\labelsep
    \setlength{\linewidth}{\columnwidth}%
}
\makeatother

\newcounter{partscounter}
\newcounter{subpartscounter}
\newcounter{subsubpartscounter}

\begin{document}
    \begin{questions}
        \columnratio{0.6,0.4}
        \begin{paracol}{2}\sloppy
            \begin{leftcolumn}
                \question \Blindtext[1][3]
                \begin{parts}
                    \part \Blindtext[1][3]
                    \begin{subparts}
                        \subpart[1] \Blindtext[1][3]
                        
                        \droppoints
                        
                        \subpart[1] \Blindtext[1][3]
                        \setcounter{subpartscounter}{\value{subpart}}
                    \end{subparts}
                    \setcounter{partscounter}{\value{partno}}
                \end{parts}
            \end{leftcolumn}
            \begin{rightcolumn}
                \includegraphics[width=\linewidth]{graphic.png}
            \end{rightcolumn}
        \end{paracol}
        
        \begin{subparts}
            \setcounter{subpart}{\value{subpartscounter}}
            \subpart \Blindtext[1][3]
            \begin{subsubparts}
                \subsubpart[1] \Blindtext[1][3]
                
                \subsubpart[1] \Blindtext[1][3]
                
                \subsubpart[1] \Blindtext[1][3]
            \end{subsubparts}
        \end{subparts}
        \begin{parts}
            \setcounter{partno}{\value{partscounter}}
            \part[1] \Blindtext[1][3]
        \end{parts}
    \end{questions}
\end{document}

This version uses the minimum width needed (assuming the number of questions can exceed 9 by less than 20_.

\documentclass[a4paper,
draft,
12pt]{exam}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[pangram]{blindtext}
\usepackage{graphicx}
\usepackage{paracol}

\pointformat{/\thepoints}
\addpoints
\pointsdroppedatright 



%%%Exercises numbering%%%
%%% https://tex.stackexchange.com/questions/682327/exam-class-define-questionlabel-and-partlabel-conditionally/682446#682446 %%%
\makeatletter
\renewcommand{\thequestion}{\arabic{question}\@ifundefined{r@part@\arabic{question}@1}{\phantom{.0}}{.0}}
\renewcommand{\thepartno}{\arabic{question}.\arabic{partno}\@ifundefined{r@subpart@\arabic{question}@\arabic{partno}@1}{\phantom{.0}}{.0}}
\renewcommand{\thesubpart}{\arabic{question}.\arabic{partno}.\arabic{subpart}\@ifundefined{r@subsubpart@\arabic{question}@\arabic{partno}@\arabic{subpart}@1}{\phantom{.0}}{.0}}
\renewcommand{\thesubsubpart}{\arabic{question}.\arabic{partno}.\arabic{subpart}.\arabic{subsubpart}}
\renewcommand{\questionlabel}{\thequestion\hfill}
\renewcommand{\partlabel}{\hbox to \labelwidth{\thepartno\hfill}}
\renewcommand{\subpartlabel}{\hbox to \labelwidth{\thesubpart\hfill}}
\renewcommand{\subsubpartlabel}{\hbox to \labelwidth{\thesubsubpart\hfill}}
\newcommand{\multihook}{%
  \setlength{\@totalleftmargin}{0pt}%
  \settowidth{\labelwidth}{12.2.2.2}% 2 is usually the widest digit, 1 is narrowest
  \setlength{\leftmargin}{\dimexpr \labelwidth+\labelsep}%
  \setlength{\linewidth}{\columnwidth}%
}
\let\questionshook=\multihook
\let\partshook=\multihook
\let\subpartshook=\multihook
\let\subsubpartshook=\multihook
\makeatother

\newcounter{partscounter}
\newcounter{subpartscounter}
\newcounter{subsubpartscounter}

\begin{document}
    \begin{questions}
        \columnratio{0.6,0.4}
        \begin{paracol}{2}\sloppy
            \begin{leftcolumn}
                \question \Blindtext[1][3]
                \begin{parts}
                    \part \Blindtext[1][3]
                    \begin{subparts}
                        \subpart[1] \Blindtext[1][3]
                        
                        \droppoints
                        
                        \subpart[1] \Blindtext[1][3]
                        \setcounter{subpartscounter}{\value{subpart}}
                    \end{subparts}
                    \setcounter{partscounter}{\value{partno}}
                \end{parts}
            \end{leftcolumn}
            \begin{rightcolumn}
                \includegraphics[width=\linewidth]{graphic.png}
            \end{rightcolumn}
        \end{paracol}
        \begin{subparts}
            \setcounter{subpart}{\value{subpartscounter}}
            \subpart \Blindtext[1][3]
            \begin{subsubparts}
                \subsubpart[1] \Blindtext[1][3]
                
                \subsubpart[1] \Blindtext[1][3]
                
                \subsubpart[1] \Blindtext[1][3]
            \end{subsubparts}
        \end{subparts}
        \begin{parts}
            \setcounter{partno}{\value{partscounter}}
            \part[1] \Blindtext[1][3]
        \end{parts}
    \end{questions}
\end{document}
3
  • Thanks! Could you please point out how you managed to contain the text in the left column for the first paracol environment? As it swapped over into the right column with my code and I cannot spot the relevant change in your code...
    – Photon
    Commented Oct 16, 2023 at 16:53
  • Since the width was set as \textwidth, it simply overlapped the right colomn. Commented Oct 17, 2023 at 15:25
  • Ah, now I get it! Thanks, it works now!
    – Photon
    Commented Oct 17, 2023 at 16:26
0

I found a workaround: Make a distinct paracol environment around each item, leaving the right column empty. Then add the graphic into the last paracol's right column and shift it up with a negative \vspace*. Not the most elegant solution but it works. Searching for better solutions though!

You must log in to answer this question.

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