XSIM-Package 解决方案环境中 TASKS 前无换行符

XSIM-Package 解决方案环境中 TASKS 前无换行符

是否有可能避免 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}

PDF 输出:

答案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}

结果:

在此处输入图片描述

相关内容