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:
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:
minipage
environment. When I want to resume the list after it, I just add\setcounter{partno}{}
to the last previous item.