我的练习表包含两列问题。每个问题都有要点,这些要点将在右侧或左侧显示为 [***]。我正在使用exsheets
包。它提供了一种默认runin
样式,我通过以下方式全局设置它\usepackage[headings=runin]{exsheets}
然后我定义一个新的样式如下
\DeclareInstance{exsheets-heading}{runinn}{default}{
runin = true ,
attach = { main[l,vc]points[l,vc](-\marginparsep-3em,0pt) } ,
join =
{
main[r,vc]title[r,vc](0pt,0pt) ;
main[r,vc]number[l,vc](.333em,0pt)
}
}
我的计划是动态检测某个问题是否被分配到右列或左列(环境
multicol
),然后为其分配一次性样式runin
或runinn
。我不知道该怎么做。左列应有左对齐的点,右列应有右对齐的点。默认提供的样式
runin
可以很好地完成“右”的工作。但我的糟糕样式runinn
无法完成“左”的工作。
我尝试使用类似这样的变体,
points-pre-code = \flushright , points-post-code = \endflushright
除了引发编译错误(这让我很困惑)外,它也没有起到什么作用。甚至points-pre-code = \raggedleft
或points-pre-code = \raggedright
什么都没有改变。
这是我的 MWE
\documentclass{article}
\usepackage{multicol,tikz}
\usepackage[headings=runin]{exsheets}
% exsheets settings
\newcommand{\rowpoints}[1]{\reversemarginpar[\foreach\x in {1,...,#1} {$\star$}]}
\SetupExSheets{counter-format=[qu]}
\SetupExSheets[question]{name=}
\SetupExSheets[points]{name=,number-format=\rowpoints}
\newcommand{\sample}{Can you answer this profoundest question of life - if two objects are greater than a third one, are they greater or smaller than each other?}
\DeclareInstance{exsheets-heading}{runinn}{default}{
runin = true ,
%points-pre-code = \flushright ,
%points-post-code = \endflushright,
%points-pre-code = \raggedright ,
attach = { main[l,vc]points[l,vc](-\marginparsep-3em,0pt) } ,
join =
{
main[r,vc]title[r,vc](0pt,0pt) ;
main[r,vc]number[l,vc](.333em,0pt)
}
}
\begin{document}
\begin{multicols}{2}
\SetupExSheets{headings=runinn}
\begin{question}{1}
This one shd have a right margin
\end{question}
\SetupExSheets{headings=runinn}
\begin{question}{2}
This one shd have a right margin
\end{question}
\SetupExSheets{headings=runinn}
\begin{question}{3}
This one shd have a right margin
\end{question}
\SetupExSheets{headings=runinn}
\begin{question}{4}
This one shd have a right margin. \sample
\end{question}
\SetupExSheets{headings=runinn}
\begin{question}{5}
This one shd have a right margin
\end{question}
\SetupExSheets{headings=runin}
\begin{question}{1}
This one shd have a left margin
\end{question}
\SetupExSheets{headings=runin}
\begin{question}{2}
This one shd have a left margin
\end{question}
\SetupExSheets{headings=runin}
\begin{question}{3}
This one shd have a left margin \sample
\end{question}
\SetupExSheets{headings=runin}
\begin{question}{4}
This one shd have a left margin
\end{question}
\SetupExSheets{headings=runin}
\begin{question}{5}
This one shd have a left margin
\end{question}
\end{multicols}
\end{document}
这就是它的样子
在此 MWE 中,我已手动尝试解决 (1),这是最糟糕的解决方案。 (2) 尚未解决。有什么帮助吗?
编辑1: 我之前发布了部分答案,删除该答案后将其合并到这里。
以下解决问题(2)
% a new question display style which fills the left margin
\DeclareInstance{exsheets-heading}{runinn}{default}{
runin = true,
points-post-code = \space,
number-post-code = \space,
attach = { main[l,vc]points[r,vc](0pt,0pt) },
join = { main[r,vc]title[r,vc](0pt,0pt);
main[r,vc]number[l,vc](.333em,0pt) }
}
将上述内容纳入新的 MWE 中:
\documentclass{article}
\usepackage{multicol,tikz,tasks}
\usepackage[headings=runin]{exsheets}
% exsheets settings
\newcommand{\rowpoints}[1]{\reversemarginpar[\foreach\x in {1,...,#1} {$\star$}]}
\SetupExSheets{counter-format=[qu]}
\SetupExSheets[question]{name=}
\SetupExSheets[points]{name=,number-format=\rowpoints}
\newcommand{\sampletext}{Can you answer this profoundest question of life - if two objects are greater than a third one, are they greater or smaller than each other?}
% a new question display style which fills the left margin
\DeclareInstance{exsheets-heading}{runinn}{default}{
runin = true,
points-post-code = \space,
number-post-code = \space,
attach = { main[l,vc]points[r,vc](0pt,0pt) },
join = { main[r,vc]title[r,vc](0pt,0pt);
main[r,vc]number[l,vc](.333em,0pt) }
}
\SetupExSheets{headings=runinn} % this new style is set as default
\settasks{
counter-format =(tsk[a]),
item-indent = 0em,
label-offset=.4em,
label-align=right,
before-skip = 0pt,
after-item-skip=0pt
}
\begin{document}
\begin{multicols}{2}
\begin{question}{1}
This one shd have a right margin
\begin{tasks}(2)
\task $n$ is even
\task $n$ is odd
\task no such $n$ exists
\task None
\end{tasks}
\end{question}
\begin{question}{2}
This one shd have a right margin \sampletext
\end{question}
\begin{question}{4}
This one shd have a right margin.
\end{question}
% I am forced to manually insert this line at an appropriate place, which is found only after seeing the PDF output.
\SetupExSheets{headings=runin} % runin is a built-in style from exsheets package
\begin{question}{5}
This one shd have a left margin.
\end{question}
\begin{question}{5}
This one shd have a left margin \sampletext \\
\end{question}
\begin{question}{1}
This one shd have a left margin \sampletext
\end{question}
\end{multicols}
\end{document}
给我以下结果。
第一个问题仍未解决。我不得不手动将其插入\SetupExSheets{headings=runin}
到适当的位置以使边距正确。不用说,这非常累人。每次将新问题添加到工作表后,我都必须删除该行并将其插入到新位置。
我尝试过\zposx
自动化等方法……但即使过了两天,我仍然无能为力。有什么想法吗?
答案1
对于 来说,这很棘手exsheets
。使用指定的继任者会容易得多xsim
:
\documentclass{article}
\usepackage[colaction]{multicol}
\usepackage{xsim,marginnote}
\xsimsetup{exercise/template=runin}
\ExplSyntaxOn
\NewExpandableDocumentCommand \makecopies {mm}
{ \prg_replicate:nn {#1} {#2} }
\ExplSyntaxOff
\usepackage{needspace}
\DeclareExerciseEnvironmentTemplate{runin}{%
\par\vspace{\baselineskip}
\Needspace*{2\baselineskip}
\noindent
\textbf{[\GetExerciseProperty{counter}]}%
\GetExercisePropertyT{subtitle}{ \textit{#1}} %
\GetExercisePropertyT{points}{%
\docolaction
{\reversemarginpar\marginnote{[\makecopies{\PropertyValue}{$\star$}]}}
{[\makecopies{\PropertyValue}{$\star$}] }
{\marginnote{[\makecopies{\PropertyValue}{$\star$}]}}%
}%
}
{}
\newcommand{\sample}{Can you answer this profoundest question of life -- if two
objects are greater than a third one, are they greater or smaller than each
other?}
\newcommand{\sampleanswer}{Yes. No. Maybe. Can you repeat the question?}
\begin{document}
\begin{multicols}{2}
\begin{exercise}[points=1]
This should have a left margin.
\end{exercise}
\begin{exercise}[points=2]
\sample
\end{exercise}
\begin{exercise}[points=3]
\sample
\end{exercise}
\begin{exercise}[points=4]
\sample
\end{exercise}
\begin{exercise}[points=5]
\sample
\end{exercise}
\begin{exercise}[points=1]
\sample
\end{exercise}
\begin{exercise}[points=2]
\sample
\end{exercise}
\begin{exercise}[points=3]
\sample
\end{exercise}
\begin{exercise}[points=4]
\sample
\end{exercise}
\begin{exercise}[points=5]
\sample
\end{exercise}
\end{multicols}
\end{document}
答案2
受到 clemens 的使用启发,\docolaction
我找到了一个勉强可行的答案。这在某些情况下有效,但对其他一些情况并不完美。在这个 MWE 中,我设置了问题的数量和内容,以突出显示不起作用的情况。第二列的第一个问题(并且只有那个问题)没有正确显示边距点。我猜那是因为leftmar
当当前要打印的行在左列时会应用标题,但在打印时,问题被移到了右列,因此边距保持为左列。如果我的question
正文较大,就不会发生这种情况。
我正在使用\savesymbol
包savesym
首先保存环境\question
/\endquestion
然后再重复使用。
\documentclass{article}
\usepackage{tikz,tasks,savesym}
\usepackage[colaction]{multicol}
\usepackage[headings=runin]{exsheets}
% exsheets settings
\newcommand{\rightrowpoints}[1]{[\foreach\x in {1,...,#1} {$\star$}]}
\newcommand{\leftrowpoints}[1]{\reversemarginpar[\foreach\x in {1,...,#1} {$\star$}]}
\SetupExSheets{counter-format=[qu]}
\SetupExSheets[question]{name=}
\SetupExSheets[points]{name=,number-format=\rightrowpoints}
\newcommand{\sampletext}{Can you answer this profoundest question of life - if two objects are greater than a third one, are they greater or smaller than each other?}
% a new question display style which fills the left margin
\DeclareInstance{exsheets-heading}{leftmar}{default}{
runin = true,
points-post-code = \space,
number-post-code = \space,
attach = { main[l,vc]points[r,vc](0pt,0pt) },
join = { main[r,vc]title[r,vc](0pt,0pt);main[r,vc]number[l,vc](.333em,0pt) }
}
\settasks{
counter-format =(tsk[a]),
item-indent = 0em,
label-offset=.4em,
label-align=right,
before-skip = 0pt,
after-item-skip=0pt
}
\savesymbol{question}
\savesymbol{endquestion}
\newenvironment{question}[1]{
\docolaction{\SetupExSheets{headings=leftmar}}{}{\SetupExSheets{headings=runin}}%
\origquestion{#1}
}{
\origendquestion\ignorespacesafterend
}
\begin{document}
\begin{multicols}{2}
\begin{question}{1}
This one shd have a right margin
\begin{tasks}(2)
\task $n$ is even
\task $n$ is odd
\task no such $n$ exists
\task None
\end{tasks}
\end{question}
\begin{question}{2}
This one shd have a right margin \sampletext
\end{question}
\begin{question}{4}
This one shd have a right margin. %\sampletext
\end{question}
\begin{question}{4}
This one shd have a right margin.
\end{question}
\begin{question}{5}
This one shd have a left margin.
\end{question}
\begin{question}{5}
This one shd have a left margin \sampletext \\
\end{question}
\begin{question}{1}
This one shd have a left margin \sampletext
\end{question}
\end{multicols}
\end{document}
它看起来是这样的(这里问题 4 展示了这种行为)-