如何在任务环境中设置边距和对齐参数?

如何在任务环境中设置边距和对齐参数?

我想知道如何控制tasks环境的三个方面:

  • 如何消除任务计数器前的无关空间,
  • 如何控制任务之间的间隔
  • 如何统一设置段落格式

在以下示例中,我希望任务编号15与左边距齐平。我还想在任务之间添加空格,以便例如任务56不会太靠近。最后,我希望设置每个任务中的段落格式,而\raggedright无需手动执行此操作。

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[margin=1in]{geometry}
\newcommand\sample{This is a sample sentence that spans more than one line of the final documents.}
\usepackage{tasks}
\usepackage{enumitem}
\setlength{\parindent}{0pt}
\begin{document}

\noindent
\raisebox{0pt}[0pt][0pt]{\rule[-4in]{0.4pt}{4in}}%%

\sample \sample \sample
\begin{tasks}[counter-format={\bfseries tsk[1].}](4)
  \task This 
  \task that 
  \task something else
  \task something even more
  \task \sample \sample
  \task \sample more more more
  \task \raggedright\texttt{\detokenize{\raggedright}} set here. \sample
  \task something
\end{tasks}

\end{document}

在此处输入图片描述

答案1

设置column-sep=1em, item-indent=1.3333em 会产生您想要的结果:

在此处输入图片描述

长度定义为

在此处输入图片描述

我认为item-offset应该如此label-offset

笔记:

  • 默认值为label-width=1emlabel-offset=0.3333em。因此,设置item-indent=1.3333em将产生与边距对齐的任务计数器。

  • 因此设置该值的默认值column-sep=0pt将增加水平间距。

  • 你可以设置\raggedright 并且\begin{tasks}将对所有的都有效tasks

代码:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[margin=1in]{geometry}
\newcommand\sample{This is a sample sentence that spans more than one line of the final documents.}
\usepackage{tasks}
\usepackage{enumitem}
\setlength{\parindent}{0pt}
\begin{document}

\noindent
\raisebox{0pt}[0pt][0pt]{\rule[-4in]{0.4pt}{4in}}%%

\sample \sample \sample
{\raggedright%
\begin{tasks}[counter-format={\bfseries tsk[1].}, column-sep=1em, item-indent=1.3333em](4)
  \task This 
  \task that 
  \task something else
  \task something even more
  \task \sample \sample
  \task \sample more more more
  \task \raggedright\texttt{\detokenize{\raggedright}} set here. \sample
  \task something
\end{tasks}}

\end{document}

答案2

这是一个解决方案,借助etoolbox最后一个要求的包:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[margin=1in, showframe, nomarginpar]{geometry}
\newcommand\sample{This is a sample sentence that spans more than one line of the final documents.}
\usepackage{tasks}
\usepackage{enumitem}
\setlength{\parindent}{0pt}
\usepackage{etoolbox}

\AtBeginEnvironment{tasks}{\raggedright}
\settasks{column-sep=1.5em, item-indent=1.3333em}%

\begin{document}

\noindent
\raisebox{0pt}[0pt][0pt]{\rule[-4in]{0.4pt}{4in}}%%

\sample \sample \sample
\begin{tasks}[counter-format={\bfseries tsk[1].}](4)
  \task This
  \task that
  \task something else
  \task something even more
  \task \sample \sample
  \task \sample more more more
  \task \raggedright\texttt{\detokenize{\raggedright}} set here. \sample
  \task something
\end{tasks}

\end{document} 

在此处输入图片描述

相关内容