免費論壇 繁體 | 簡體
Sclub交友聊天~加入聊天室當版主
分享
返回列表 发帖

为 tasks 增加左右 margin

tasks 宏包是用来输入像以下格式的列表:
QQ截图20210727163605.png
2021-7-27 17:02

详细介绍及用法请自行用命令行运行 texdoc tasks 查看。
可调的参数很多,但缺少整体左右 margin 的设置,比如说,默认下:
QQ截图20210727163856.png
2021-7-27 17:02

(这里用其自带的 debug 参数显示了边框)
如果想让 a) 右移,移到比段首缩进更进,就只能增加 item-indent(默认 2.5em),比如增加到 4em ,结果是:
QQ截图20210727163912.png
2021-7-27 17:02

标号是右移了,但右边界没变,结果就是实际上相邻列距变大,内容宽度就窄了很多。
而其实我想要的是这样:
QQ截图20210727164208.png
2021-7-27 17:02

但我找遍 tasks 的文档都没找到类似于 left 或 leftmargin 之类的参数项,后来在 texlive 安装目录下的 texmf-dist 里搜索 tasks.sty ,找到后打开,再查找 margin ,看到:
QQ截图20210727164816.png
2021-7-27 17:02

看来是被定死了,于是我尝试修改它。
当然最好不要改变原文件,把 tasks.sty 复制到当前 tex 文档所在目录下再改即可,因为运行时是优先读取当前目录的文件的。
QQ截图20210727165813.png
2021-7-27 17:02

保存后,就可以在正文中用 \lmg=1.5em 来改变 leftmargin ,效果就是前面我想要的那个。
还可以设 rightmargin ,比如再加 \rmg=2.5em ,效果:
QQ截图20210727170123.png
2021-7-27 17:02

也可以随时改回去。

【注】对于不同版本的 tasks ,要修改的那段代码可能不同,所以这里不贴完整代码,只给出新增和修改的几句:
  1. 前面新增:
  2. \newlength\lmg\setlength\lmg{0pt}
  3. \newlength\rmg\setlength\rmg{0pt}
  4. 后面修改为:
  5.         \dim_set:Nn \leftmargin  {\lmg}
  6.         \dim_set:Nn \rightmargin {\rmg}
复制代码
然后请自行操作。

测试文档:
  1. \documentclass{article}
  2. \usepackage{tasks}
  3. \parindent=2em
  4. \newcount\n
  5. \newcommand\kk[1]{\loop\ifnum\n<\numexpr#1-1\relax
  6. . . . . . . . . \advance\n by1\repeat\n=0. . . . . . . .}

  7. \begin{document}

  8. \kk9

  9. \begin{tasks}(4)
  10. \task the first
  11. \task the second
  12. \task the third
  13. \task the fourth
  14. \task*(3) the fifth item is way too long for this and needs three columns
  15. \task the sixth
  16. \task the seventh
  17. \task*(2) the eighth item is way too long for this and needs two columns
  18. \task the nineth
  19. \task the tenth
  20. \end{tasks}

  21. \settasks{debug}

  22. \kk9

  23. \begin{tasks}(4)
  24. \task \kk2 \task \kk3 \task \kk4 \task \kk5
  25. \end{tasks}

  26. \kk9

  27. \begin{tasks}[item-indent=4em](4)
  28. \task \kk2 \task \kk3 \task \kk4 \task \kk5
  29. \end{tasks}

  30. \kk9

  31. \lmg=1.5em

  32. \begin{tasks}(4)
  33. \task \kk2 \task \kk3 \task \kk4 \task \kk5
  34. \end{tasks}

  35. \kk9

  36. \rmg=2.5em

  37. \begin{tasks}(4)
  38. \task \kk2 \task \kk3 \task \kk4 \task \kk5
  39. \end{tasks}

  40. \kk9

  41. \end{document}
复制代码
分享到: QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
$\href{https://kuingggg.github.io/}{\text{About Me}}$

返回列表 回复 发帖