4

I believe I have a compatibility problem with center environment and the breakable tcolorbox package.

What I'm doing is:

\usepackage[breakable]{tcolorbox}
\tcbset{before=\begin{center}, after=\end{center}, width=0.8\linewidth, colback=blue!20!white, colframe=blue!70!white, boxrule=0.3mm, toptitle=1.5mm, bottomtitle=1.5mm}

The document is compiled but with some errors:

\begin{center} on input line 53 ended by \end{tcolorbox}. \end{tcolorbox}
\begin{tcolorbox} on input line 43 ended by \end{center}. \end{tcolorbox}
Missing } inserted. \end{tcolorbox}
Too many }'s. \end{tcolorbox}

Beforehand, I appreciate your help!

3
  • 1
    Make a complete example so that other can try it out without having to guess and type the necessary code. Oct 15, 2015 at 7:24
  • 1
    As a side-effect of avoiding other problems, environments cannot be used by before and after for breakable boxes. But both answers of Christian Hupfer and Harish Kumar show good alternatives to achieve the centering. Oct 15, 2015 at 14:26
  • 1
    @ThomasF.Sturm: Besides that: Using \begin{center}...\end{center} for just one breakable tcolorbox isn't too much typing at all.
    – user31729
    Oct 15, 2015 at 19:32

3 Answers 3

4

There is no need for etoolbox. tcolorbox has facilities for this.

When you say width=0.8\linewidth,, to make the box centered, you have to push it to right by 0.1\linewidth. This can be done by

,enlarge left by=0.1\linewidth,
%% enlarge right by=0.1\linewidth  %% if needed from right

So this code (template stolen from Christian Hupfer) works as intended.

\documentclass{article}
\usepackage{showframe}
\usepackage[breakable]{tcolorbox}

\newtcolorbox{brokenbox}[1][]{width=0.8\linewidth, colback=blue!20!white, colframe=blue!70!white, boxrule=0.3mm, toptitle=1.5mm, bottomtitle=1.5mm,breakable,enlarge left by=0.1\linewidth,#1}


\usepackage{blindtext}

\begin{document}

\begin{brokenbox}[colback=yellow]
  \blindtext[5]
\end{brokenbox}

\end{document}

enter image description here

4
  • Bad boy!!!!!!!!!!!!
    – user31729
    Oct 15, 2015 at 9:13
  • @ChristianHupfer No. Ugly boy! ;-)
    – user11232
    Oct 15, 2015 at 9:17
  • Hey Harish and @ChristianHupfer, thank you guys... you solved my problem! Oct 16, 2015 at 4:08
  • @MateoVasco You are welcome :)
    – user11232
    Oct 16, 2015 at 4:11
3

The breaking mechanism uses individual tcolorbox enviroments and I assume that the verbatim way of tcolorbox provides wrong \end{tcolorbox} code for the last box -- the \end{center} is lost.

Using \BeforeBeginEnvironment and \AfterEndEnvironment from the etoolbox package this can be circumvented:

\documentclass{article}
\usepackage{etoolbox}
\usepackage[breakable]{tcolorbox}

\newtcolorbox{brokenbox}[1][]{width=0.8\linewidth, colback=blue!20!white, colframe=blue!70!white, boxrule=0.3mm, toptitle=1.5mm, bottomtitle=1.5mm,breakable,#1}


\usepackage{blindtext}


\BeforeBeginEnvironment{brokenbox}{%
\begin{center}
}

\AfterEndEnvironment{brokenbox}{%
\end{center}
}

\begin{document}

\begin{brokenbox}[colback=yellow]
  \blindtext[5]
\end{brokenbox}

\end{document}

enter image description here

1

As a complement to the two other answers which already solve the problem, here is third possibility. Instead of restricting the width of the box to 0.8\linewidth followed by some centering method, the left skip and right skip values could be set to 0.1\linewidth. Technically, this changes the bounding box and gives the same effect as the answer by Harish Kumar.

\documentclass{article}
\usepackage{showframe}
\usepackage[breakable]{tcolorbox}

\newtcolorbox{brokenbox}[1][]{
  % width=0.8\linewidth,          <---- removed
  leftright skip=0.1\linewidth,%  <---- added
  colback=blue!20!white,
  colframe=blue!70!white,
  boxrule=0.3mm,
  toptitle=1.5mm,
  bottomtitle=1.5mm,
  breakable,
  #1}

\usepackage{blindtext}

\begin{document}

\begin{brokenbox}[colback=yellow]
  \blindtext[5]
\end{brokenbox}

\end{document}

You must log in to answer this question.

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