是否有可能避免 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}
答案1
一个快速的解决方法是将任务选项设置before-skip
为负值和\vspace
在代码中的任务环境之前包含负数(垂直空间)。请注意,您需要\vspace
在每个任务环境之前手动添加。
我还将提供的更改mytemplate
为手册runin
中描述的模板xsim
,因为给定的模板在处理多个问题时无法正确缩进。我将\parbox
带有下划线的练习编号的部分复制到runin
模板中并将其命名为myrunin
。请注意,此模板需要needspace
包。
梅威瑟:
\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}
结果: