4

I have a document full of nicely formatted and separated paragraphs (each separated by two line breaks in the source), which is working nicely. Now I'd like to put some of them into a tcolorbox.

But when the text is inside a tcolorbox, all paragraph breaks are replaced by simple line breaks!

Is there a way I can get normal formatting inside a tcolorbox?

MWE (I'd like the first three and last three paragraphs formatted the same):

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

\setlength{\parskip}{1em}

\begin{document}

\begin{tcolorbox}
\lipsum[1]

\lipsum[2]

\lipsum[3]
\end{tcolorbox}

\lipsum[4]

\lipsum[5]

\lipsum[6]
\end{document}
  • Looks like tcolorbox redefines \parskip, but adding it inside the tcolorbox, e.g. after \begin{tcolorbox}, fixes the issue. – user121799 Nov 14 '18 at 3:05
  • @marmot So it does! Is there a way to automatically prepend that to every one of my tcolorboxes? If so that would make a good answer, and I'd accept. – Draconis Nov 14 '18 at 3:06
  • Whether you separate your paragraphs in the source by one or by twenty-seven blank lines will change nothing in the output. – thymaro Nov 14 '18 at 3:08
8

You can set the parbox key to false:

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

\setlength{\parskip}{1em}

\begin{document}

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

\lipsum[2]

\lipsum[3]
\end{tcolorbox}

\lipsum[4]

\lipsum[5]

\lipsum[6]
\end{document}

enter image description here

5

I cannot give you an answer that works for all imaginable tcolorbox variations as these can have upper and lower and you-know-not parts (I'm exaggerating a bit, I know;-). However, for your simple scenario one way to smuggle the desired \parskip (or whatever setting) inside the tcolorbox is to say \tcbset{before upper=\setlength{\parskip}{1em}}. Whether or not a more universal way exists, I don't know.

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

\setlength{\parskip}{1em}
\tcbset{before upper=\setlength{\parskip}{1em}}
\begin{document}

\begin{tcolorbox}
\lipsum[1]

\lipsum[2]

\lipsum[3]
\end{tcolorbox}

\lipsum[4]

\lipsum[5]

\lipsum[6]
\end{document}

enter image description here

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.