36

I am using the tcolorbox to provide some beautiful frames around certain parts of my document; I use the parskip to give nice spacing between paragraphs.

When I have more than one paragraph inside a tcolorbox the parskip is not obeyed, as highlighted in the screen shot below. I have searched the manual, but it seems to describe before and after skips, but not 'during'. How can this be fixed?

screenshot

Here's a complete MWE that demonstrates the problem:

% arara: pdflatex
\documentclass{article}

\usepackage{tcolorbox}
\usepackage{lipsum}
\usepackage{parskip}

\begin{document}

\begin{tcolorbox}
\lipsum[1]

\lipsum[2]
\end{tcolorbox}

\lipsum
\end{document}
lockstep
  • 250,273
cmhughes
  • 100,947

2 Answers2

36

Yes, there is a native tcolorbox solution. The content of a tcolorbox is processed with the typical settings of parbox and minipage. You can switch this kind processing by setting parbox=false to do a mimicry of 'normal' processing.

You find this in the tcolorbox documentation as Text Characteristics (4.18 Text Characteristics on p. 98, for current tcolorbox version 4.22 [2019/11/15]).

\documentclass{article}

\usepackage{tcolorbox}
\usepackage{lipsum}
\usepackage{parskip}

\begin{document}

\begin{tcolorbox}[parbox=false]
\lipsum[1]

\lipsum[2]
\end{tcolorbox}

\lipsum
\end{document}

enter image description here

Stefan Pinnow
  • 29,535
  • 1
    Awesome, thanks so much :) Sorry I missed this in the documentation :) I love your package, thanks so much for all of the work that you have done :) – cmhughes Jan 20 '14 at 16:50
  • 1
    I also missed that option in the documentation; fortunately we have you here :-) – Gonzalo Medina Jan 20 '14 at 18:36
  • @GonzaloMedina My subsection title Text Characteristics may also be better chosen ... ;-) – Thomas F. Sturm Jan 21 '14 at 06:37
  • +1: Just what I needed! – Dr. Manuel Kuehner Aug 10 '20 at 16:25
  • If I use parbox=false, it doesn't work to put the environment first in an enumerate item, because then the left side of the box will cut into the item number. Is it possible to move indent the left side of the box (move it to the right) without also moving the number? I've tried using enlarge left by=1cm, but then the number is also moved. – StrawberryFieldsForever Feb 28 '21 at 14:17
  • Exactly what I needed, I was building the same MWE before stackoverflowing this issue :D – 3isenHeim Apr 19 '21 at 08:22
9

One option would be to use the settings from parskip inside a new environment defined using tcolorbox:

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}
\usepackage{parskip}

\newenvironment{mycolorbox}[1][]
  {\if\detokenize{#1}\relax\relax
      \begin{tcolorbox}
    \else
      \begin{tcolorbox}[#1]
    \fi
  \parskip=0.5\baselineskip \advance\parskip by 0pt plus 2pt
  \parindent=0pt
}
  {\end{tcolorbox}}

\begin{document}

\begin{mycolorbox}
\lipsum[1]

\lipsum[2]
\end{mycolorbox}

\lipsum

\end{document}

enter image description here

Gonzalo Medina
  • 505,128