为什么当 textcolor 或 itemize 处于活动状态时,tcolorbox 中的文本周围会添加一些垂直空间?

为什么当 textcolor 或 itemize 处于活动状态时,tcolorbox 中的文本周围会添加一些垂直空间?

如果我删除 textcolor 规范(以及相应的 2 个花括号),则“someItem”周围的无用空格就会消失。
如果我用文本替换“\begin{itemize} ... \end{itemize}”块,“someItem”周围的无用空格就会消失。

为什么会有这些差异?我尝试删除 LaTeX 源中的所有空白,因为我认为它们会导致一些问题,但这没有帮助。

它是否与“垂直模式”的概念有关(我还不明白,但有人在我的另一篇关于不需要的空间的帖子中提到过它)?

我看到一些有类似问题的帖子(例如:为什么 tcolorbox 会增加垂直空间?),也许他们的解决方案可行,但我仍然不明白我的 MWE 中的 textcolor 或 itemize 是什么问题...

我正在使用 LuaLaTex,但此在线服务的结果相同: https://latex.net/texlive/

事实上,我并不需要为我的文本添加颜色。我只是把它放在我的一个文档中来玩字体。所以我只需删除“textcolor”,我的文档就可以了,但我仍然想了解发生了什么!

\documentclass{article}%
\usepackage{tcolorbox}%
\usepackage{enumitem}%
\begin{document}%
\begin{tcolorbox}[notitle]%
{\textcolor{blue}{%
\begin{itemize}%
\item{someItem}%
\end{itemize}%
}}%
\end{tcolorbox}%
\end{document}%

文本周围不需要的垂直空间

答案1

好吧,颜色会影响间距,因为它会增加内容。如果你使用\textcolor而不是,\color你还会开始一个段落。使用 lualatex 可以使用 luacolor,这可以避免部分问题。

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{enumitem}
%\usepackage{luacolor}
\begin{document}
\begin{tcolorbox}[notitle]
\begin{itemize}
\item{someItem}
\end{itemize}
\end{tcolorbox}


\begin{tcolorbox}[notitle]
\color{blue}
\begin{itemize}
\item{someItem}
\end{itemize}
\end{tcolorbox}

\begin{tcolorbox}[notitle]
\textcolor{blue}
{\begin{itemize}
\item{someItem}
\end{itemize}}
\end{tcolorbox}

\begin{tcolorbox}[notitle]
\leavevmode
\begin{itemize}
\item{someItem}
\end{itemize}
\end{tcolorbox}
\end{document}

使用 luacolor

在此处输入图片描述

没有使用 luacolor

在此处输入图片描述

相关内容