6

The file

\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}

produces two tcolorboxes The vertical distances between the baselines of the titles and the bottom edges of the upper parts of the boxes differ, because the first title contains no characters with descenders whereas the second one contains such a character, p. I would prefer the distances to be the same. As far as I can see, none of the tcolorbox parameters produces that spacing. I can achieve it by changing the definition of \newtcbtheorem to

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

which produces two tcolorboxes So far, so good. (I realize that the \strut has increased the space above and below, but the result looks good to me. Also I realize that the vertical spaces below the text in the lower parts are uneven, but for some reason I find that less bothersome.)

But now suppose that the title extends to the second line. Then the spacing is uneven again: two tcolorboxes I could manually add a \vphantom{p} at the end of every two-line title, but there must be a better solution. Any ideas?

(This question relates to the same issue, but the answer involves manually modifying the text in the upper part. I'm looking for a solution that will work globally, without modifications to the text in specific boxes.)

1
  • Congrats, very good question and very well formulated!
    – CarLaTeX
    Mar 3, 2022 at 6:50

2 Answers 2

5

As the problem is with the last line of titles, you can also use after title app hook to add \strut there.

\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}

enter image description here

1
  • That works! Adding, in addition, before title app=\strut means that I don't need to put \strut at the start of the second argument of \newtcbtheorem. (And I can put after title app=\strut and before title app=\strut in my \tcbset settings, so that I don't have to include any extra code in every \newtcbtheorem.) Mar 4, 2022 at 2:25
4

I think you can solve your problem with 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}

enter image description here

2
  • This answer perfectly solves the problem I posed and was posted first, both of which are reasons why I should accept it. But I think that the answer by @Ignasi is slightly better because it works even for a definition that has no title, whereas this answer fails in that case --- because then there is no description around which to put delimiters, I guess. Mar 4, 2022 at 2:21
  • @MartinJ.Osborne Don't worry, Ignasi's answer is more correct, I upvoted it.
    – CarLaTeX
    Mar 4, 2022 at 6:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .