LaTeX的tasks宏包

tasks 宏包

LaTeX的列表(list)通常是将项(item,条目)一个一个垂直的平行显示,所谓“列”表的由来。
水平分列列表,即将多个项分散到各列而不是一列,在出考卷的选择题时常碰到,LaTeX中的包有:enumcols(enumlists)、tasks(exsheets)
enumcols宏包是李清创建的,TeXlive 2018后,与CTeX的模板冲突。本篇主要讨论tasks宏包的使用。tasks宏包的主要用法如下:

\begin{tasks}[<选项>](<列数>)
    \task item1
    \task item2
\end{tasks}

例:选择题的文档

\documentclass{ctexart}
% 导言区添加
\usepackage{tasks}
\settasks{                     %设置
    counter-format=tsk[A],     %编号
    label-format={\bfseries},  %加粗
    %item-indent={-0.1em},
    %label-offset={-0.05em}
}

% 测试用
\newcommand{\sample}{This is some sample text we will use to create a somewhat longer text spanning a
few lines. This is some sample text we will use to create a somewhat longer text
spanning a few lines}


\begin{document}

选择题有4个选项,分4列显示选项A,B,C,D。

\begin{enumerate}
    \begin{tasks}(4)
        \task $x^2 + y^2 = R^2$
        \task $\mathrm{E}=\mathrm{MC}^2$
        \task $e^{-i\pi} = 1$
        \task \sample
    \end{tasks}
\end{enumerate}

\end{document}

例:跨越多个列的项

\begin{tasks}(4)
    \task \sample
    \task* \texttt{*}占用后面的所有列\sample
    \task* 占用后面的所有列\sample
    \task*(2) \texttt{*}本身可以带选项,指定占用的列数\sample
    \task*[(x)] 指定该条目的编号为(x)
    \startnewitemline
    \task! 另起新条目并占用以后的所有列\sample
    \task \sample
\end{tasks}

基于tasks定义新列表环境

\NewTasks{itemtasks}[\item] %以\item为分隔符

% 文档中
\begin{itemtasks}(3)
    \item \sample
    \item \sample
    \item \sample
\end{itemtasks}

使用如下定义的环境mytasks不能嵌套在enumerate环境,提示
“begin{mytasks} on input line 22 ended by \end{itemtasks}”

“\begin{itemtasks} on input line 22 ended by \end{document}”

\NewTasks{itemtasks}[\item]    % 以\item为分隔符
\newenvironment{mytasks}[1][2]{
    \begin{itemtasks}(#1)
}{
    \end{itemtasks}
}

% 文档中
\begin{enumerate}
    \item 第一个问题选项如下
        \begin{mytasks}[2]
            \item $x^2 + y^2 = R^2$
            \item $\mathrm{E}=\mathrm{MC}^2$
            \item $e^{-i\pi} = 1$
            \item \sample
        \end{mytasks}
\end{enumerate}

mytasks是按照\NewEnviron(xparse包)定义的,标准的环境定义方法使用\itemtasks...\enditemtasks

\newenvironment{mytasks}[1][2]{
    \itemtasks(#1)
}{
\enditemtasks
}

% 文档中
\begin{enumerate}
    \item 第一个问题选项如下
        \begin{mytasks}[4]
            \item $x^2 + y^2 = R^2$
            \item $\mathrm{E}=\mathrm{MC}^2$
            \item $e^{-i\pi} = 1$
            \item \sample
        \end{mytasks}
\end{enumerate}

使用environ'包的\NewEnviron`命令定义

\NewTasks{itemtasks}[\item]        % 以\item为分隔符

\usepackage{environ}
\NewEnviron{mytasksenv}[1][2]{
    \def\tempbegin{\begin{itemtasks}(#1)} 
            \expandafter\tempbegin\BODY 
        \end{itemtasks}
}{}

% 文档中
\begin{mytasksenv}[4]
    \item $x^2 + y^2 = R^2$
    \item $\mathrm{E}=\mathrm{MC}^2$
    \item $e^{-i\pi} = 1$
    \item $x^2 + y^2 = R^2$
\end{mytasksenv}

使用xparse'包的\NewDocumentEnvironment`定义

\usepackage{xparse}
\NewDocumentEnvironment{mytasksx}{}
  {\newTask(2)}
  {\endnewTask}

猜你喜欢

转载自www.cnblogs.com/ourweiguan/p/11005432.html