0

Following David Purton advice:

I have a tcolorbox which may run accross pages, thus it is set as breakable.

But I sometimes use it inside minipage and it gets broken (presumably as minipage are not breakable) even when not running accross pages.

The question is: how can I check if my tcolorbox is inside a minipage and set its breakable option to false?

MWE:

\documentclass{article}

\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\tcbset{breakable}

\usepackage{lipsum}

\begin{document}
\lipsum[1-5]

\begin{minipage}{.3\textwidth}
    left side
\end{minipage}\hfill
\begin{minipage}{.65\textwidth}
    \begin{tcolorbox}
        Text here   
        \begin{itemize}
            \item list item here
            \item and here
            \item and here
        \end{itemize}
    \end{tcolorbox}
\end{minipage}

\begin{tcolorbox}
    Text here   
    \begin{itemize}
        \item list item here
        \item and here
        \item and here
    \end{itemize}
\end{tcolorbox}
\end{document}
3
  • I think my answer in your previous question can avoid this one: tex.stackexchange.com/a/588420/1952
    – Ignasi
    Mar 22 at 10:21
  • I think this one is still relevant as it allows one box setup to cover all needs. After all, breakable means "can be split" and not "will be split", no? But for sure, the width and nobeforeafter parameters are a possible solution. Thank you for that.
    – Ivan
    Mar 23 at 16:40
  • For the record: Ignasi comment answer to the previous question has been accepted as it actually answers the question.
    – Ivan
    Mar 23 at 22:16
0

You can manually set \tcbset{breakable=false} inside the minipage with bad breaks. For example:

 \begin{minipage}{.65\textwidth}
  \tcbset{breakable=false}
  \begin{tcolorbox}
   Text here   
   \begin{itemize}
    \item list item here
    \item and here
    \item and here
   \end{itemize}
  \end{tcolorbox}

You can get the same result with:

\begin{tcolorbox}[breakable=false]
...
\end{tcolorbox}

Better, you can set it globally with:

\usepackage{etoolbox}
  \pretocmd{\minipage}{\tcbset{breakable=false}}{}{}

or without etoolbox:

\makeatletter
\def\minipage{%
 \tcbset{breakable=false}%
 \@ifnextchar[%]
 \@iminipage
 {\@iiiminipage c\relax[s]}}
\makeatother

MWE

\documentclass{article}

\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\tcbset{breakable}
\usepackage{lipsum}

\usepackage{etoolbox}
\pretocmd{\minipage}{\tcbset{breakable=false}}{}{}

\begin{document}
 \lipsum[1-5]
 
 \begin{minipage}{.3\textwidth}
  left side
 \end{minipage}\hfill
 \begin{minipage}{.65\textwidth}
  \begin{tcolorbox}
   Text here   
   \begin{itemize}
    \item list item here
    \item and here
    \item and here
   \end{itemize}
  \end{tcolorbox}
 \end{minipage}
 
 \begin{tcolorbox}
  Text here   
  \begin{itemize}
   \item list item here
   \item and here
   \item and here
  \end{itemize}
 \end{tcolorbox}

\end{document}

enter image description here

2
  • I had to check twice that you were not me as I did not remember knowing the solution and posting it. Maybe I should get some sleep now :) Thank you Ivan, I take the etoolbox solution.
    – Ivan
    Mar 21 at 13:02
  • 1
    You can avoid etoolbox if you do not use it for other purposes as well. I edited the answer adding another solution.
    – Ivan
    Mar 21 at 13:12

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.