1

Does anyone know how to get wrapfigure to play well with breakable tcolorboxes?

Two pairs of illustrations and code examples follow. The first example uses tcolorbox with the breakable setting, and without wrapfigure. It shows that the tcolorbox breaks as expected at the end of the first page (the snapshot is of the bottom left corner of page 1 and the top left corner of page 2).

The second example then enables wrapfigure for the tcolorbox. The compiler recognizes that the tcolorbox should break at the end of the page, but it does not carry this out as one would like. (The code in the second example differs only in the definition of \sidebox: the wrapfigure code is uncommented, and accordingly, a trivial adjustment is made to the tcolorbox width.)

Is there any way to get the desired behavior?

Apologies for having to redefine lipsum in the MWE but it has to be the right length otherwise you can't see the problem.

First illustration follows:

MWE without wrapfigure enabled

Second illustration follows:

MWE with wrapfigure enabled

Code for first illustration:

\documentclass[letterpaper,12pt]{memoir}
\usepackage[english]{babel}

\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\usepackage{wrapfig}

\newcommand{\sidebox}[1]%
    {%
%   \setlength{\intextsep}{0pt}%    
%   \begin{wrapfigure}{l}{3cm}%
%       \begin{tcolorbox}[width=\linewidth,valign=center,breakable]%
        \begin{tcolorbox}[width=0.2\linewidth,valign=center,breakable]%
            #1%
        \end{tcolorbox}%
%       \end{wrapfigure}%
    }%

\newcommand{\mylipsum}{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.}

\begin{document}

\sidebox{the quick brown fox jumps over the lazy dog and jumps again and again and again}

\mylipsum

\sidebox{the quick brown fox jumps over the lazy dog and jumps again and again and again}

\mylipsum

\sidebox{the quick brown fox jumps over the lazy dog and jumps again and again and again}

\mylipsum

\end{document}

Code for second illustration:

\documentclass[letterpaper,12pt]{memoir}
\usepackage[english]{babel}

\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\usepackage{wrapfig}

\newcommand{\sidebox}[1]%
    {%
    \setlength{\intextsep}{0pt}%    
    \begin{wrapfigure}{l}{3cm}%
        \begin{tcolorbox}[width=\linewidth,valign=center,breakable]%
%       \begin{tcolorbox}[width=0.2\linewidth,valign=center,breakable]%
            #1%
        \end{tcolorbox}%
        \end{wrapfigure}%
    }%

\newcommand{\mylipsum}{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.}

\begin{document}

\sidebox{the quick brown fox jumps over the lazy dog and jumps again and again and again}

\mylipsum

\sidebox{the quick brown fox jumps over the lazy dog and jumps again and again and again}

\mylipsum

\sidebox{the quick brown fox jumps over the lazy dog and jumps again and again and again}

\mylipsum

\end{document}
3
  • I'm afraid this isn't possible with the facilities of wrapfig as it boxes the contents, so no, not without extensive work and then not with wrapfig.
    – Skillmon
    Commented Nov 10, 2021 at 14:38
  • I'm not sure about the real problem but did you look at magazine library? It can break tcolorboxes in several parts which are printed later as you need them.
    – Ignasi
    Commented Nov 10, 2021 at 15:31
  • Thanks for the suggestion of magazine. It looks like it could provide a solution, but the implementation would be tricky and beyond the powers of my little brain.
    – 35royan2
    Commented Nov 20, 2021 at 19:35

1 Answer 1

2

This looks like a job for paracol! The one drawback is that you have to manually break the last paragraph to wrap the text. Search here for \splitpar and \continuepar.

\documentclass[letterpaper,12pt]{memoir}
\usepackage[english]{babel}
\usepackage{lipsum}

\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\usepackage{paracol}

\newcommand{\sidebox}[1]%
    {%
        \begin{tcolorbox}[width=\linewidth,valign=center,breakable]% or \columnwidth
            #1%
        \end{tcolorbox}%
    }%


\begin{document}

\setcolumnwidth{3cm}
\begin{paracol}{2}
\sidebox{the quick brown fox jumps over the lazy dog and jumps again and again and again}

\sidebox{the quick brown fox jumps over the lazy dog and jumps again and again and again}

\sidebox{the quick brown fox jumps over the lazy dog and jumps again and again and again}

\sidebox{the quick brown fox jumps over the lazy dog and jumps again and again and again}

\switchcolumn
\lipsum[1-4]
\end{paracol}
\end{document}
1
  • I tried out this paracol approach and it is a good workaround, so I upvoted it. It doesn't quite do what I wanted, but it comes close and it's easy to implement.
    – 35royan2
    Commented Nov 20, 2021 at 19:37

You must log in to answer this question.

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