2

I am using the xsim package to create exercise sets. Some exercises begin immediately with parts (a), (b) etc and no introductory text. I've used other answers from here to set up an enumitem list with topsep = 0pt and negative vspace for the 'before'. This seems fine in most cases, except for exercise 2 in this example where the superscript appears to affect the vertical alignment.

Is there a better way to set up the enumitem list so that part (a) will always align correctly with the exercise number?

\documentclass[a4paper,11pt]{memoir}
\usepackage[T1]{fontenc} 
\usepackage[defaultsans]{opensans}
\usepackage{newtxtext,newtxmath}

\setlength{\parskip}{0.6em}
\setlength{\parindent}{0pt}

\usepackage{xsim}

\DeclareExerciseEnvironmentTemplate{margin}  % simulate margin-nr style from exsheets
{%
\par\vspace{\baselineskip}
\Needspace*{2\baselineskip}
\noindent
\llap{%
\smash{%
\tabular[t]{@{}r@{}}
\sffamily\textbf{\GetExerciseProperty{counter}\,}
\endtabular
} % notice the space
}%
}
{}

\xsimsetup{
    exercise/template = margin,
    solution/template = margin
}

\usepackage{enumitem}
\newlist{exampartsnoskip}{enumerate}{2}
\setlist[exampartsnoskip]{topsep=0pt,before={\vspace*{-1.85em}},label={(\alph*)},itemsep=0.1em,leftmargin=\oddsidemargin}
\setlist[exampartsnoskip,1]{label=(\alph*)}


\begin{document}

\begin{exercise}
\begin{exampartsnoskip}
    \item First
    \item Second
\end{exampartsnoskip}
\end{exercise}

\begin{exercise}
\begin{exampartsnoskip}
\item Evaluate $\left(36^\frac12+16^\frac14\right)^\frac13$
\item Second
\end{exampartsnoskip}
\end{exercise}

\begin{exercise}
\begin{exampartsnoskip}
    \item $\dfrac{x}{\dfrac{1}{x+1}}$
    \item Second
\end{exampartsnoskip}
\end{exercise}

\end{document}

Screenshot of aligment problem in exercise 2

2

Maybe implement the margin template with a trivlist:

\documentclass[a4paper,11pt]{memoir}
\usepackage[T1]{fontenc} 
\usepackage[defaultsans]{opensans}
\usepackage{newtxtext,newtxmath}

\setlength{\parskip}{0.6em}
\setlength{\parindent}{0pt}

\usepackage{showframe}

\usepackage{xsim}

\DeclareExerciseEnvironmentTemplate{margin}{%
  \trivlist
  \item[\llap{\sffamily\textbf{\GetExerciseProperty{counter}}}]\relax
}
{\endtrivlist}

\xsimsetup{
  exercise/template = margin,
  solution/template = margin
}

\usepackage{enumitem}
\newlist{examparts}{enumerate}{2}
\setlist[examparts]{
  topsep=0pt,
  % before={\vspace*{-1.85\baselineskip}},
  label={(\alph*)},
  itemsep=0.1em,
  leftmargin=\oddsidemargin
}
\setlist[examparts,1]{label=(\alph*)}

\begin{document}

\begin{exercise}
  \begin{examparts}
    \item First
    \item Second
  \end{examparts}
\end{exercise}

\begin{exercise}
  \begin{examparts}
    \item Evaluate $\left(36^\frac12+16^\frac14\right)^\frac13$
    \item Second
  \end{examparts}
\end{exercise}

\begin{exercise}
  \begin{examparts}
    \item $\dfrac{x}{\dfrac{1}{x+1}}$
    \item Second
  \end{examparts}
\end{exercise}

\end{document}

enter image description here

  • I like how this solution also obviates the negative vspace that I had set in the enumerate environment which always felt like a kludge. – sxpmaths Jul 5 '17 at 7:56
2

enter image description here

If you want the over-sized height of the inner expression to affect the position of the outer label number you need to delay setting that number and then tack it on to the inner label. LaTeX does something similar by default for nested lists but here I just do it by hand.

\documentclass[a4paper,11pt]{memoir}
\usepackage[T1]{fontenc} 
\usepackage[defaultsans]{opensans}
\usepackage{newtxtext,newtxmath}

\setlength{\parskip}{0.6em}
\setlength{\parindent}{0pt}

\usepackage{xsim}

\DeclareExerciseEnvironmentTemplate{margin}  % simulate margin-nr style from exsheets
{%
\par\vspace{\baselineskip}
\Needspace*{2\baselineskip}
\protected\gdef\exno{\llap{%
\sffamily\textbf{\GetExerciseProperty{counter}\,} }% notice the space
\gdef\exno{}}%
}
{}

\xsimsetup{
    exercise/template = margin,
    solution/template = margin
}

\usepackage{enumitem}
\newlist{exampartsnoskip}{enumerate}{2}
\setlist[exampartsnoskip]{topsep=0pt,before={\vspace*{-1.85em}},label={(\alph*)},itemsep=0.1em,leftmargin=\oddsidemargin}
\setlist[exampartsnoskip,1]{label=\exno(\alph*)}


\begin{document}

\begin{exercise}
\begin{exampartsnoskip}
    \item First
    \item Second
\end{exampartsnoskip}
\end{exercise}

\begin{exercise}
\begin{exampartsnoskip}
\item Evaluate $\left(36^\frac12+16^\frac14\right)^\frac13$
\item Second
\end{exampartsnoskip}
\end{exercise}

\begin{exercise}
\begin{exampartsnoskip}
    \item $\dfrac{x}{\dfrac{1}{x+1}}$
    \item Second
\end{exampartsnoskip}
\end{exercise}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.