3

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

  • 1
    I find most environments really annoying to use with setspace, not just tcolorbox. But what about beforeafter skip=\baselineskip as an option? It will probably make the space be a little larger on both sides than your 'double spacing', but it should hopefully look 'even'.... – jon Mar 17 '17 at 3:27
  • I found that attach title to upper, after title=\par\noindent solves the issue between the box title and body in this case. – Elmar Peise Mar 17 '17 at 9:16
  • Ah, well, if that works for you, consider posting an answer to your own question, and accepting the answer that best answers the question. (This takes the question off the 'unanswered questions' list.) – jon Mar 17 '17 at 17:06
  • @jon It really only fixes one of the three spaces, so I wouldn't consider it a solution. – Elmar Peise Mar 17 '17 at 18:23
  • You should edit your question, then. (Or ask a new one.) Your understanding of the issue and what is being asked here are starting to diverge. – jon Mar 17 '17 at 19:10
1

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}
  • This looks like a good alternative (with the parindent is removed). However, I also need other tcolorbox features, such as numbering, labeling, "Table of" listing, and most importantly breakable. – Elmar Peise Mar 17 '17 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.