Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange distancing when starting with a bulleted enviroment. #116

Open
Sk1nk opened this issue Aug 26, 2023 · 1 comment
Open

Strange distancing when starting with a bulleted enviroment. #116

Sk1nk opened this issue Aug 26, 2023 · 1 comment

Comments

@Sk1nk
Copy link

Sk1nk commented Aug 26, 2023

I noticed that the spacing is of if I start a (centered) exercise with an itemize or enumerate enviroment.

Minimal working example:

\documentclass[%
a4paper,			
]{memoir}

\usepackage{cmbright}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[clear-aux]{xsim}
\xsimsetup{
	load-style=layouts,
	exercise/template=centered,
	solution/print = false,	
	exercise/name = Aufgabe,
	blank/filled-style=\textcolor{Red}{#1},
	blank/line-minimum-length = 1cm,
	blank/scale = 1.5,
}		

\begin{document}
\begin{exercise}
Normal 	distance between header and text!
\end{exercise}

\begin{exercise}
\begin{enumerate}
	\item Greater distance between header and text!
\end{enumerate}
\end{exercise}
	
\end{document}

produces
Bildschirmfoto 2023-08-26 um 11 54 46

@muzimuzhi
Copy link

With the default setting exercise/template=default, exercise title is typeset by \subsection*{<title>}, which takes care of vertical spacing between following list (like enumerate) automatically, through \@afterheading.

With exercise/template=centered, the same exercise title is now typeset manually, by \hfil\textbf{<title>}...\hfil\par\noindent. This time the vertical space \topsep inserted by a list environment (between it and the previous text) is not ignored automatically any more.

Implementations of exercise templates default and centered

xsim/code/xsim.sty

Lines 5509 to 5533 in 06e3dba

\DeclareExerciseEnvironmentTemplate {default}
{
\GetExerciseHeadingF { \subsection* }
{
\XSIMmixedcase { \GetExerciseName } \nobreakspace
\GetExerciseProperty {counter}
\IfInsideSolutionF
{
\IfExercisePropertySetT {subtitle}
{ ~ { \normalfont \itshape \GetExerciseProperty {subtitle} } }
}
}
\GetExercisePropertyT {points}
{
\marginpar
{
\IfInsideSolutionF { \rule {1.2cm} {1pt} \slash }
\printgoal {\PropertyValue}
\GetExercisePropertyT {bonus-points}
{ \nobreakspace ( + \printgoal {\PropertyValue} ) }
\nobreakspace\XSIMtranslate {point-abbr}
}
}
}
{ \par }

\DeclareExerciseEnvironmentTemplate{centered}
{%
\par\vspace{\baselineskip}
\Needspace*{2\baselineskip}
\noindent
\hfil\textbf{\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}}%
\GetExercisePropertyT{subtitle}{ \textit{#1}}\hfil
\par\noindent
\IfInsideSolutionF{%
\GetExercisePropertyT{points}{%
\marginpar{%
\printgoal{\PropertyValue}%
\GetExercisePropertyT{bonus-points}{+\printgoal{\PropertyValue}}%
\,\IfExerciseGoalSingularTF{points}
{\XSIMtranslate{point}}
{\XSIMtranslate{points}}%
}%
}%
}%
}
{}

Adding back \@afterheading (manually or by patching the centered template) solves the problem, partially. Note with exercise/template=centered, if exercise property points is given for an exercise starting with a list environment, the value of points will be typeset in its own paragraph, as a marginal note. You may need to manually adjust the vertical spacing.

\documentclass{article}
\usepackage{lipsum}

% to show distances between baseline heights
\usepackage{lineno}
\renewcommand{\thelinenumber}{\arabic{linenumber}\rlap{\rule{.4pt}{11pt}}}
\linenumbers

%\usepackage{cmbright}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[clear-aux]{xsim}
\xsimsetup{
	load-style=layouts,
	exercise/template=centered,
}

\makeatletter
% cheat `xsim` as if `centered` template is undefined
\ExpandArgs{cc}\relax {cs_undefine:N} {l__xsim_template_begin_centered_setup_tl}
\ExpandArgs{cc}\relax {cs_undefine:N} {l__xsim_template_end_centered_setup_tl}

\DeclareExerciseEnvironmentTemplate{centered}
  {%
    \par\vspace{\baselineskip}
    \Needspace*{2\baselineskip}
    \noindent
    \hfil\textbf{\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}}%
    \GetExercisePropertyT{subtitle}{ \textit{#1}}\hfil
    \par\noindent\@afterheading % <<< changed
    \IfInsideSolutionF{%
      \GetExercisePropertyT{points}{%
          \marginpar{%
            \printgoal{\PropertyValue}%
            \GetExercisePropertyT{bonus-points}{+\printgoal{\PropertyValue}}%
            \,\IfExerciseGoalSingularTF{points}
                {\XSIMtranslate{point}}
                {\XSIMtranslate{points}}%
          }%
      }%
    }%
  }
  {}
\makeatother

\begin{document}
\begin{exercise}[subtitle={no points + plain text}]
  Normal distance between header and text!
\end{exercise}

\begin{exercise}[subtitle={no points + list}]
  \begin{enumerate}
  	\item Greater distance between header and text!
  \end{enumerate}
\end{exercise}

\begin{exercise}[points=2, subtitle={points + plain text}]
  Normal distance between header and text!
\end{exercise}

\begin{exercise}[points=3, subtitle={points + list}]
  \begin{enumerate}
  	\item Greater distance between header and text!
  \end{enumerate}
\end{exercise}

\begin{exercise}[points=4, subtitle={points + list + manual adjustment}]
  \vspace{-\baselineskip}
  \begin{enumerate}
  	\item Greater distance between header and text!
  \end{enumerate}
\end{exercise}

\section*{Emulation}
\subsection*{EnvironmentTemplate=default}
\lipsum[2][1]

\subsection*{EnvironmentTemplate=default}
\begin{enumerate}
  \item \lipsum[2][1]
\end{enumerate}

\hfil\textbf{EnvironmentTemplate=centered}\hfil \par
\lipsum[2][1]

\hfil\textbf{EnvironmentTemplate=centered}\hfil \par
\begin{enumerate}
  \item \lipsum[2][1]
\end{enumerate}

\hfil\textbf{EnvironmentTemplate=centered, patched}\hfil \par
\UseName{@afterheading}%
\begin{enumerate}
  \item \lipsum[2][1]
\end{enumerate}
\end{document}

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants