[Tex/LaTex] Natural vertical space before tcolorbox with increased line spacing

setspacetcolorbox

I use double line spacing through \doublespacing from setspace and I want to highlight some parts of my text with a simple tcolorbox. I want the text to be spaced equally across the box's boundaries and title. However, as the MWE below shows, the space before and after the title is too small and the space after the box is too large.

My questions:

  • Why is this happening?
  • What is the most natural solution?

I have played with before, top, size, etc. and I can probably make it "look about right". But I'm interested in a solution that is "right by design", i.e., one that accounts for the (variable) line spacing and inserts spaces accordingly.

EDIT: The space between the box title and content can be fixed with attach title to upper, after title=\par\nobreak\noindent; this removes the title box altogether.

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{setspace}
\tcbuselibrary{skins}
\doublespacing
\begin{document}
    I'm the first paragraph to demonstrate normal spacing between paragraphs.

    I'm the paragraph before the box.  I'm long enough to demonstrate the double line spacing.

    \begin{tcolorbox}[
        blanker, left=1em, borderline west={1pt}{0pt}{gray},
        fonttitle=\color{black}\bf, adjusted title=I'm the title line,
    ]
        I'm the paragraph in the box.  I'm also long enough to demonstrate the double line spacing.
    \end{tcolorbox}

    I'm the paragraph after the box.
\end{document}

Output:
enter image description here

Best Answer

There are many vertical lengths in a tcolorbox to make their own space Thus, instead of fight with options before, after, after skip, etc., to look like there is not any tcolorbox, I would make my own macro with a simple vertical box:

\def\vrgbox#1#2{
\vspace{\abovedisplayskip}
{\color{gray}\vrule width 1pt}\hskip1em 
\vbox{\hsize\dimexpr\linewidth-1em-1pt-\parindent \parindent0pt
{\bfseries #1}\par#2}}

Or a minipage:

\def\vrgbox#1#2{\vspace{\abovedisplayskip}
{\color{gray}\vrule width 1pt}\hskip1em
\begin{minipage}{\dimexpr\linewidth-\parindent-1em-1pt}
{\bfseries#1}\par#2\end{minipage} }

In both cases the result is:

mwe

THe MWE with the second macro:

\documentclass{article}
\usepackage{xcolor}
\usepackage{setspace}
\doublespacing
\def\vrgbox#1#2{\vspace{\abovedisplayskip}
{\color{gray}\vrule width 1pt}\hskip1em
\begin{minipage}{\dimexpr\linewidth-\parindent-1em-1pt}
{\bfseries#1}\par#2\end{minipage} }

\begin{document}

I'm the first paragraph to demonstrate 
normal spacing between paragraphs.

I'm the paragraph before the box.  
I'm long enough to demonstrate the double line spacing.

\vrgbox{Im the title line}{I'm the paragraph in the box.  
I'm also long enough to demonstrate the double line spacing.}

I'm the paragraph after the box.

\end{document}