tcolorbox 标题文本周围的垂直间距

tcolorbox 标题文本周围的垂直间距

文件

\documentclass[12pt]{article}
\usepackage{xparse}
\usepackage[many]{tcolorbox}

\newtcbtheorem{definition}{Definition}{
  colback=red!5,
  colframe=red!70}{d}

\begin{document}

\begin{definition}{Title that has no descenders}{}
No character in the title  has a descender.
\end{definition}

\begin{definition}{Title with a descender present}{}
The title includes a character, p, with a  descender.
\end{definition}

\end{document}

生产 两个 tcolorbox 标题基线与框上部底部边缘之间的垂直距离不同,因为第一个标题不包含带降部的字符,而第二个标题包含这样的字符 p。我希望距离相同。据我所知,没有一个参数会tcolorbox产生该间距。我可以通过更改 的定义来\newtcbtheorem实现

\newtcbtheorem{definition}{\strut Definition}{
  colback=red!5,
  colframe=red!70}{d}

产生 两个 tcolorbox 到目前为止,一切都很好。(我意识到\strut增加了上方和下方的空间,但结果对我来说看起来不错。我还意识到下部文本下方的垂直空间不均匀,但出于某种原因,我发现这不那么麻烦。)

但现在假设标题延伸到第二行。那么间距又不均匀了: 两个 tcolorbox 我可以手动\vphantom{p}在每两行标题末尾添加一个,但一定有更好的解决方案。有什么想法吗?

这个问题与同一问题有关,但答案涉及手动修改上部的文本。我正在寻找一种可以全局使用的解决方案,而无需修改特定框中的文本。)

答案1

由于问题出在标题的最后一行,您也可以使用after title app钩子在那里添加\strut

\documentclass[12pt]{article}
\usepackage{xparse}
\usepackage[many]{tcolorbox}

\newtcbtheorem{definition}{Definition}{
  colback=red!5,
  colframe=red!70, 
  after title app=\strut}{d}

\begin{document}

\begin{definition}{Title that with no descenders}{}
No character in the title  has a descender.
\end{definition}

\begin{definition}{Title with a descender present}{}
The title includes a character, p, with a  descender.
\end{definition}

\begin{definition}{Title that with no descenders - The same box with a two-line title}{}
No character in the title  has a descender.
\end{definition}

\begin{definition}{Title with a descender present - The same box with a two-line title with a p}{}
The title includes a character, p, with a  descender.
\end{definition}

\end{document}

在此处输入图片描述

答案2

我认为你可以用以下方法解决你的问题description delimiters={\strut}{\strut}

\documentclass[12pt]{article}
\usepackage{xparse}
\usepackage[many]{tcolorbox}

\newtcbtheorem{definition}{Definition}{
  description delimiters={\strut}{\strut},
  colback=red!5,
  colframe=red!70}{d}

\begin{document}

\begin{definition}{Title that with no descenders}{}
No character in the title  has a descender.
\end{definition}

\begin{definition}{Title with a descender present}{}
The title includes a character, p, with a  descender.
\end{definition}

\begin{definition}{Title that with no descenders - The same box with a two-line title}{}
No character in the title  has a descender.
\end{definition}

\begin{definition}{Title with a descender present - The same box with a two-line title with a p}{}
The title includes a character, p, with a  descender.
\end{definition}

\end{document}

在此处输入图片描述

相关内容