0

Is it possible to avoid linebreak before tasks in xsim?


\documentclass{article}
\usepackage{xsim,tasks,ulem}
\loadxsimstyle{layouts}

\xsimsetup{%     
 exercise/template = mytemplate ,
 solution/template = mytemplate
}

\DeclareExerciseEnvironmentTemplate{mytemplate}
{%
\par\medskip
    \parbox{0.05\textwidth}{
    \textbf{\uline{\GetExerciseProperty{counter}\hfill 
    }}}
    \parskip6pt 
    \parindent10pt 
    \raggedright
    \hangindent=0.06\textwidth
    \hangafter1
     \rmfamily 
    }{
    \par\ignorespaces
    \medskip
    }

\settasks{
    label-width=12pt,
    label-offset=6pt, 
    item-indent = 0.06\textwidth+18pt, 
    column-sep = 3pt, 
    after-skip = -6pt, 
    after-item-skip = 1pt
}

\begin{document}

\section*{Exercises} 

\begin{exercise}
The question concerne the solution.  
\end{exercise}  
\begin{solution} 
    \begin{tasks}(2)
        \task Here I like to start on the same line
        \task So it is more compact
    \end{tasks}    
\end{solution} 
 


\printsolutions

\end{document}

PDF-Output:

1 Answer 1

1

A quick workaround is to set the tasks option before-skip to a negative value and to include negative \vspace (vertical space) just before the tasks environment in the code. Note that you need to add \vspace manually before every tasks environment.

I also changed the provided mytemplate to the runin template described in the xsim manual, because the given template did not indent properly with more than one question. I copied the \parbox part with the underlined exercise number into the runin template and called it myrunin. Note that this template requires the needspace package.

MWE:

\documentclass{article}
\usepackage{xsim,tasks,ulem}
\usepackage{needspace}
\loadxsimstyle{layouts}

\xsimsetup{%     
 exercise/template = myrunin ,
 solution/template = myrunin
}

% copied from tasks manual
\DeclareExerciseEnvironmentTemplate{myrunin}
{%
\par\vspace{\baselineskip}
\Needspace*{2\baselineskip}
\noindent
\parbox{0.05\textwidth}{%
    \textbf{\uline{\GetExerciseProperty{counter}\hfill% 
    }}}%
\GetExercisePropertyT{subtitle}{ \textit{#1}} % <<< notice the space
\IfInsideSolutionF{%
\GetExercisePropertyT{points}{%
\marginpar{%
\printgoal{\PropertyValue}%
\GetExercisePropertyT{bonus-points}{+\printgoal{\PropertyValue}}%
\,\IfExerciseGoalSingularTF{points}
{\XSIMtranslate{point}}
{\XSIMtranslate{points}}%
}%
}%
}%
}
{}

\settasks{
    label-width=12pt,
    label-offset=6pt, 
    item-indent = 0.06\textwidth+18pt, 
    column-sep = 3pt,
    before-skip = -12pt, % set before skip to negative value
    after-skip = -6pt, 
    after-item-skip = 1pt
}

\begin{document}

\section*{Exercises} 

\begin{exercise}
The question concerne the solution.  
\end{exercise}
\begin{solution} 
    \vspace{-12pt} % add negative vertical space
    \begin{tasks}(2)
        \task Here I like to start on the same line
        \task So it is more compact
    \end{tasks}
\end{solution} 
\begin{exercise}
Another exercise
\end{exercise}
\begin{solution}
This exercise is unsolvable
\end{solution} 

\printsolutions

\end{document}

Result:

enter image description here

You must log in to answer this question.

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