我正在使用 xsim 包来创建练习集。有些练习立即以部分 (a)、(b) 等开始,没有介绍性文字。我使用了此处的其他答案来设置枚举列表,其中 topsep = 0pt 和负 vspace 作为“before”。这在大多数情况下似乎没问题,但本例中的练习 2 除外,其中上标似乎影响了垂直对齐。
有没有更好的方法来设置 enumitem 列表,以便部分 (a) 始终与练习编号正确对齐?
\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}
答案1
也许margin
使用以下方式实现模板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}
答案2
如果您希望内部表达式的过大高度影响外部标签数字的位置,则需要延迟设置该数字,然后将其附加到内部标签上。LaTeX 默认对嵌套列表执行类似操作,但在这里我只是手动执行。
\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}