LaTeX的tasks宏包

摘要:
任务列表宏包LaTeX通常垂直并行地逐个显示项目。所谓“列”表的起源。水平列列表,即多个项目分布到每一列而不是一列。它经常出现在试卷的多项选择题中。LaTeX中的包包括:由李青创建的enumcolumns(enumlist)、tasks(exsheets)enumcolumn宏包。TeXlive2018之后,它与CTeX的模板冲突。本文主要讨论任务宏包的使用。任务
tasks 宏包

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

egin{tasks}[<选项>](<列数>)
    	ask item1
    	ask item2
end{tasks}

例:选择题的文档

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

% 测试用

ewcommand{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}


egin{document}

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

egin{enumerate}
    egin{tasks}(4)
        	ask $x^2 + y^2 = R^2$
        	ask $mathrm{E}=mathrm{MC}^2$
        	ask $e^{-ipi} = 1$
        	ask sample
    end{tasks}
end{enumerate}

end{document}

例:跨越多个列的项

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

基于tasks定义新列表环境

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

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

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

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

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

ewenvironment{mytasks}[1][2]{
    egin{itemtasks}(#1)
}{
    end{itemtasks}
}

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

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


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

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

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

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

usepackage{environ}
NewEnviron{mytasksenv}[1][2]{
    def	empbegin{egin{itemtasks}(#1)} 
            expandafter	empbeginBODY 
        end{itemtasks}
}{}

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

使用xparse'包的NewDocumentEnvironment`定义

usepackage{xparse}
NewDocumentEnvironment{mytasksx}{}
  {
ewTask(2)}
  {endnewTask}

完整的示例

%!TEX program = xelatex
documentclass[UTF8]{ctexart}

usepackage{url}
usepackage{tasks}
settasks{
	counter-format=tsk[A],
	label-format={fseries},
	%item-indent={-0.1em},
	%label-offset={-0.05em}
}

NewTasks{itemtasks}[item]
%
ewenvironment{mytasks}[1][2]{
%	egin{itemtasks}(#1)
%}{
%	end{itemtasks}
%}


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

%https://tex.stackexchange.com/questions/237230/tasks-in-custom-environment
usepackage{environ}
NewEnviron{mytasksenv}[1][2]{
	def	empbegin{egin{itemtasks}(#1)} 
			expandafter	empbeginBODY 
		end{itemtasks}
}{}

usepackage{xparse}
%https://tex.stackexchange.com/questions/391459/nesting-tasks-within-an-xparse-environment
NewDocumentEnvironment{mytasksx}{}
  {itemtasks(2)}
  {enditemtasks}


ewcommand{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}

egin{document}

egin{mytasksenv}[4]
	item six, 继续上面的编号.
	item seven
	item seven
	item seven
end{mytasksenv}

egin{enumerate}
	item 第一个问题选项如下
		egin{mytasks}[2]
			item $x^2 + y^2 = R^2$
			item $mathrm{E}=mathrm{MC}^2$
			item $e^{-ipi} = 1$
			item sample
		end{mytasks}
end{enumerate}


egin{tasks}(4)
		ask* 一般使用格式为	exttt{\begin{tasks}[选项](列数)}
		ask 可使用	exttt{*}
		ask three
end{tasks}

egin{tasks}[resume=true]
		ask six, 继续上面的编号.
		ask seven
end{tasks}

This is some sample text we will use to create a somewhat longer text spanning a
few lines.

egin{enumerate}
	item 在LyX中,定义新环境itemtasks,用item分隔符!不会与外面的item冲突!但是LyX插入的选项放在中括号汇总,而tasks要求放在小括号中。
	item url{http://troubleshooters.com/linux/lyx/ownlists.htm}不知道说啥
	item 第二个问题有如下的选项
		egin{tasks}(4)
				ask $x^2 + y^2 = R^2$
				ask $mathrm{E}=mathrm{MC}^2$
				ask $e^{-ipi} = 1$
				ask sample
		end{tasks}
	item 第三
		egin{tasks}(2)
				ask $x^2 + y^2 = R^2$
				ask $mathrm{E}=mathrm{MC}^2$
				ask $e^{-ipi} = 1$
				ask $e^{-ipi} = 1$
		end{tasks}
end{enumerate}

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

end{document}

免责声明:文章转载自《LaTeX的tasks宏包》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Sublime Text 使用教程《操作系统》课程笔记(Ch08-内存管理策略)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

latex处理表格 [转]

论文写作中,有时候会遇到某一个表格水平跨度太长,但是latex不能根据页面的宽度自动断开单元格内的内容,会出现表格内容跨出文档水平长度无法显示。这里提供四种解决方案: 第一,最简单也是最初级的方法,就是缩小表格里面的内容显示字体。这种处理往往不能很好的满足一些期刊要求。 第二,使用表格中的p{width}来限定某一列的长度,比如p{5cm}。 第三,换一种...

latex小记

双栏模式下: 单张图: egin{figure}[h] centering includegraphics[width=8.0cm]{successRatio.eps} caption{ extbf{Success ratio with different algorithms}}label{successRatio} end{figure} 多张...

Latex 中文支持CJK的安装与配置

Latex中文支持CJK的安装与配置在这里记一下自己Latex中文安装与配置的方法,为还没有搞定这个问题的朋友们提供一点小小的帮助.CJK的安装包可以从这里下载得到:http://www.cjk.org我们还可以从王垠的个人主页下载一个方便安装的程序:http://learn.tsinghua.edu.cn/homepage/2001315450/tex_...

Ubuntu下安装Latex [转]

Ubuntu下LaTex中文环境配置 LaTeX是一个强大的排版软件,但是其最初只是为英文排版而设计的。为了使其能够胜任中文排版的重任,我们还需要进行一些额外的调教。这篇文章中,就谈谈如何在Ubuntu下(使用12.04)进行LaTeX中文环境配置。 第一步,安装基本的LaTeX环境: sudoapt-get installtexlive 第二步,安装中...

Ansible playbooks

Playbook是Ansible的配置,部署和编排语言。 他们可以描述您希望远程系统执行的策略,或一般IT流程中的一组步骤。 如果Ansible modules是您workshop的工具,则playbooks是您的说明手册,您的主机inventory是您的原材料。 在基本层面上,可以使用playbooks来管理远程机器的配置和部署。 在更高级别,他们可以对...

Latex插入代码程序+边框+颜色+汇编代码 [转]

listings 是专用于代码排版的 LaTeX宏包,可对关键词、注释和字符串等使用不同的字体和颜色或颜色,也可以为代码添加边框、背景等风格。 1 基本用法 下面给出一份用于排版 C 语言 HelloWorld 程序代码的完整的 LaTeX 文档: \documentclass{article}\usepackage{listings}\begin{do...