0

According to the Tasks Package documentation, nesting of the tasks environment is not supported, so I typically combine tasks with enumerate for questions with multiple parts. The issue is that loading the parskip package seems to break the alignment when an \item is immediately followed by a tasks environment:

enter image description here

Here is the corresponding MWE:

\documentclass[12pt]{article}
\usepackage{parskip}
\usepackage{tasks}
\begin{document}
    \begin{enumerate}
        \item This looks fine.
        \begin{tasks}(2)
            \task The first part
            \task The second part
        \end{tasks}
        \item \begin{tasks}(2)
            \task This doesn't though
        \end{tasks}
    \end{enumerate}
\end{document}

I should point out that there is a similar question to mine on the site, but the fix didn't work for me for some reason. I'd appreciate any help with this.

1
  • If you look carefully you can see that the alignment is off also without parskip. Commented Oct 28, 2022 at 9:54

1 Answer 1

1

You could create a custom counter for each question and then insert the counter in front of each paragraph with a formed question. This way you can avoid unnecessary nesting of two environments. tasks also accepts settings to format a list.

If \parskip is non-zero, which I think is the case in you example, the skip is also added between questions (paragraphs) and answers (environments). One way to cancel it is simply adding a negative space. However, to avoid repetition, it's possible to add a hook, which automatically appends a code before each instance of the tasks.

Here's the full code

\documentclass[12pt]{article}
\usepackage{tasks}
\usepackage{kantlipsum}
\settasks{
    label-width=12pt,
    item-indent=3em,
    before-skip=0pt,
    after-skip=0pt,
    after-item-skip=0pt,
}
\newcounter{question}
\newcommand\question{%
    \stepcounter{question}%
    \noindent%
    \makebox[1em][r]{\thequestion.}\hspace{0.5em}}
\AddToHook{env/tasks/before}{%
    \ifdim\parskip=0pt\else\vspace{-6pt}\fi}


\begin{document}
\parskip12pt\parindent0pt
\kant[1][1]
\kant[1][2]

\question Question one
\begin{tasks}(2)
    \task Answer 1
    \task Answer 2
    \task Answer 3
\end{tasks}

\question Question two
\begin{tasks}(2)
    \task Answer 1
    \task Answer 2
    \task Answer 3
    \task Answer 4
\end{tasks}

\question Question three
\begin{tasks}(2)
    \task Answer 1
    \task Answer 2
    \task Answer 3
    \task Answer 4
\end{tasks}

\kant[1][3]
\kant[1][4]
\end{document}

enter image description here

You must log in to answer this question.

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