# Odd vertical spacing with xsim

I'm trying to write the following document with xsim, using some customized templates based on the predefined ones:

\documentclass{scrartcl}%
\usepackage{lipsum}

\usepackage{xsim,mdframed}%
\xsimsetup{solution/print=true}
\DeclareExerciseEnvironmentTemplate{mtmargin}
{%
\trivlist
\item[\llap{%
\smash{%
\tabular[t]{@{}r@{\hspace{.67em}}}
{\large \sffamily \bfseries \GetExerciseProperty{counter}}
\IfExercisePropertySetT{points}{%
\tabularnewline
\sffamily \itshape (%
\printgoal{\GetExerciseProperty{points}}%
\GetExercisePropertyT{bonus-points}{+\printgoal{#1}}%
\,\XSIMtranslate{point-abbr}%
)%
}%
\endtabular
}%
}]\relax
}%
{\endtrivlist}
\DeclareExerciseEnvironmentTemplate{mtrunin-sol}{%
%\vspace{-1\baselineskip}     %% LINE 1
\mdframed \noindent
{\sffamily \bfseries \XSIMmixedcase{\GetExerciseName}.\hspace{1em}}%
}
{
\endmdframed
\par \vspace{\baselineskip}     %% LINE 2
}
\SetExerciseParameters{exercise}{
exercise-template=mtmargin,
solution-template=mtrunin-sol,
}

\begin{document}

\begin{exercise}[points=99]
\lipsum[1]
\end{exercise}
\begin{solution}
\lipsum[2]
\end{solution}
\begin{exercise}[points=99]
\lipsum[3]
\end{exercise}
\begin{solution}
\lipsum[4]
\end{solution}
\begin{exercise}[points=99]
\lipsum[5]
\end{exercise}
\begin{solution}
\lipsum[6]
\end{solution}

\end{document}


I get an unwanted vertical space between exercise and solution and I don't know where it stems from. It could be easily fixed by introducing "LINE 1" (which is commented in the code above), but this doesn't put the problem "under control" merely creating a patch. Also, if I insert "LINE 2" what I get is not a \vspace{\baselineskip} but roughly \vspace{2\baselineskip}. Any suggestion to understand this behavior? Is this issue related to the \trivlist command?

Yes, it's trivlist.

You can set \topsep to zero just before starting \trivlist:

\DeclareExerciseEnvironmentTemplate{mtmargin}
{%
\setlength{\topsep}{0pt}%
\trivlist
\item[\llap{%
\smash{%
\tabular[t]{@{}r@{\hspace{.67em}}}
{\large \sffamily \bfseries \GetExerciseProperty{counter}}
\IfExercisePropertySetT{points}{%
\tabularnewline
\sffamily \itshape (%
\printgoal{\GetExerciseProperty{points}}%
\GetExercisePropertyT{bonus-points}{+\printgoal{#1}}%
\,\XSIMtranslate{point-abbr}%
)%
}%
\endtabular
}%
}]\relax
}%
{\endtrivlist}


or use a different strategy without trivlist:

\DeclareExerciseEnvironmentTemplate{mtmargin}
{%
\noindent\makebox[0pt][r]{\smash{%
\tabular[t]{@{}r@{\hspace{.67em}}}
{\large \sffamily \bfseries \GetExerciseProperty{counter}}
\IfExercisePropertySetT{points}{%
\tabularnewline
\sffamily \itshape (%
\printgoal{\GetExerciseProperty{points}}%
\GetExercisePropertyT{bonus-points}{+\printgoal{#1}}%
\,\XSIMtranslate{point-abbr}%
)%
}%
\endtabular
}%
}%
}%
{}


• And this is the answer. Thank you very much! Jun 20 '18 at 16:09