TASKS 包对于水平列表非常有用。但是,当在 TColorBoxes 中使用 Tasks 列表时,Tasks 的行为很奇怪,在不需要时添加回车符。有没有办法恢复 Tasks 的正常行为?
\documentclass[]{book}
\usepackage{tcolorbox}
\usepackage{tasks}
\begin{document}
\tcbset{MyTasksInTColorBox/.style={
colframe=blue!70!black,
colback=blue!2!white,
fonttitle=\bfseries\huge
}}
\settasks{
label-format={\color{green!70!black}\large\bfseries},
}
\def\ContentOfBox{%
%
\bfseries Tasks in 3 columns \normalfont
\begin{tasks}[style=multiplechoice](3)
\task One
\task Two
\task Three
\task Four
\task Five
\task Six
\task Seven
\task Eight
\task Nine
\task Ten
\end{tasks}
\noindent\rule{2cm}{0.4pt}\\[2mm]
%
\bfseries Tasks in 4 columns \normalfont
\begin{tasks}[style=multiplechoice](4)
\task One
\task Two
\task Three
\task Four
\task Five
\task Six
\task Seven
\task Eight
\task Nine
\task Ten
\end{tasks}
\noindent\rule{2cm}{0.4pt}\\[2mm]
%
\bfseries Tasks in 5 columns \normalfont
\begin{tasks}[style=multiplechoice](5)
\task One
\task Two
\task Three
\task Four
\task Five
\task Six
\task Seven
\task Eight
\task Nine
\task Ten
\end{tasks}
\noindent\rule{2cm}{0.4pt}\\[2mm]
%
\bfseries Tasks in 6 columns \normalfont
\begin{tasks}[style=multiplechoice](6)
\task One
\task Two
\task Three
\task Four
\task Five
\task Six
\task Seven
\task Eight
\task Nine
\task Ten
\end{tasks}
\noindent\rule{2cm}{0.4pt}\\[2mm]
%
\bfseries Tasks in 7 columns \normalfont
\begin{tasks}[style=multiplechoice](7)
\task One
\task Two
\task Three
\task Four
\task Five
\task Six
\task Seven
\task Eight
\task Nine
\task Ten
\end{tasks}
}
\begin{tcolorbox}[MyTasksInTColorBox,title= {Tasks in (4) and (5) columns have a carriage return issue (width = linewidth)}]
\ContentOfBox
\end{tcolorbox}
\begin{tcolorbox}[MyTasksInTColorBox,width=1.1\linewidth,title= {Tasks in (5) and (7) columns have a carriage return issue (width = 1.1*linewidth)}]
\ContentOfBox
\end{tcolorbox}
\begin{tcolorbox}[MyTasksInTColorBox,width=1.2\linewidth,title= {Tasks in (5) and (6) columns have a carriage return issue (width = 1.2*linewidth)}]
\ContentOfBox
\end{tcolorbox}
\begin{tcolorbox}[MyTasksInTColorBox,width=1.3\linewidth,title= {Tasks in (4), (5), (6) and (7) columns have a carriage return issue (width = 1.3*linewidth)}]
\ContentOfBox
\end{tcolorbox}
\end{document}
答案1
tcolorbox 手册(版本 4.21)第 4.18 节讨论了该parbox=
设置:
如果框不可破坏,则 tcolorbox 中的文本将使用 LATEX minipage 进行格式化。如果可破坏,则框会尝试模仿 minipage。在 minipage 或 parbox 中,段落的格式与正文略有不同。如果将键值设置为 false,则将恢复正常的正文行为。在某些情况下,这会产生一些不良的副作用。建议您仅在真正需要此功能时才使用此实验设置。
因此,使用parbox=false
应该可以恢复正常格式。
我还添加了left=pt
并right=0pt
消除了左侧和右侧的填充
\tcbset{MyTasksInTColorBox/.style={
colframe=blue!70!black,
colback=blue!2!white,
fonttitle=\bfseries\huge,
parbox=false,
left=0pt,
right=0pt,
}}