3

I am trying to make a document so that a colorbox, in a double column book document, spans both of the columns nad I do not know what to do. Here is my test.

\documentclass[10pt,twoside,twocolumn,openany]{book}
\usepackage[most]{tcolorbox}
\usepackage{xcolor}
\usepackage{lipsum}

\definecolor{monstertan}{HTML}{FDF1DC}  %e.g. used for newer monsterblock
\definecolor{iron}{HTML}{CBCDCD}    %e.g. used for older monsterbox
\definecolor{undergold}{HTML}{C9AD6A}   % e.g. used for titlerules
\definecolor{uppergold}{HTML}{B89A67}   %e.g. used for pagenumbers and footer
\definecolor{brass}{HTML}{B5A642}
\definecolor{copper}{HTML}{b87333}
\definecolor{black}{HTML}{000000}

\DeclareTColorBox{paperbox}{O{} m O{iron}}{
    frame hidden,
    boxrule=0pt,
    breakable,
    enhanced,
    before skip=11pt plus 1pt,
    toptitle=3mm,
    boxsep=0.25ex,
    left=8pt,
    right=8pt,
    fonttitle=\fontfamily{fosj}\selectfont\scshape\bfseries\color{brass},
    fontupper=\fontfamily{lmss}\selectfont,
    title=#2,
    arc=0mm,
    parbox = false,
    borderline north={1pt}{-0.5pt}{brown},
    borderline south={1pt}{-0.5pt}{brown},
    colback=#3,
    colframe=#3,
    colbacktitle=#3,
    fuzzy shadow={0mm}{-3.5pt}{-0.5pt}{0.4mm}{black!60!white},
    overlay={
        \fill [fill=brown] (frame.south west) -- ++(7pt,0) -- ++(0,-5pt) -- cycle;
        \fill [fill=brown] (frame.north west) -- ++(7pt,0) -- ++(0,5pt) -- cycle;
        \fill [fill=brown] (frame.north east) -- ++(-7pt,0) -- ++(0,5pt) -- cycle;
        \fill [fill=brown] (frame.south east) -- ++(-7pt,0) -- ++(0,-5pt) -- cycle;
    },
    after={\vspace{10pt plus 1pt}\noindent},
    #1
}

\begin{document}
\lipsum*
\begin{paperbox}[width=200px]{lipsum}
\lipsum
\end{paperbox}
\end{document}

How do I go about doing it?

2
  • Would temporarily switching to one column be an option? \begin{onecolumn} \begin{paperbox}{lipsum} \lipsum \end{paperbox} \end{onecolumn} – samcarter_is_at_topanswers.xyz Sep 25 '17 at 18:45
  • \onecolumn and \twocolumn cause a page break. You could use multicol instead, – John Kormylo Sep 25 '17 at 20:15
8

One alternative to multicol could be cuted:

mwe

\documentclass[a4paper,twocolumn]{article}
\usepackage{cuted,tcolorbox,lipsum}
\begin{document}
\lipsum[1]
\begin{strip}
\begin{tcolorbox}[title=A tcolorbox]
    \lipsum[2]
\end{tcolorbox}
\end{strip}
\lipsum[3-6]
\end{document}
0
3

Here is a multicol solution. See also multicols inside tcolorbox

\documentclass[10pt,twoside,openany]{book}
\usepackage[most]{tcolorbox}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{multicol}

\definecolor{monstertan}{HTML}{FDF1DC}  %e.g. used for newer monsterblock
\definecolor{iron}{HTML}{CBCDCD}    %e.g. used for older monsterbox
\definecolor{undergold}{HTML}{C9AD6A}   % e.g. used for titlerules
\definecolor{uppergold}{HTML}{B89A67}   %e.g. used for pagenumbers and footer
\definecolor{brass}{HTML}{B5A642}
\definecolor{copper}{HTML}{b87333}
\definecolor{black}{HTML}{000000}

\DeclareTColorBox{paperbox}{O{} m O{iron}}{
    frame hidden,
    boxrule=0pt,
    breakable,
    enhanced,
    before skip=11pt plus 1pt,
    toptitle=3mm,
    boxsep=0.25ex,
    left=8pt,
    right=8pt,
    fonttitle=\fontfamily{fosj}\selectfont\scshape\bfseries\color{brass},
    fontupper=\fontfamily{lmss}\selectfont,
    title=#2,
    arc=0mm,
    parbox = false,
    borderline north={1pt}{-0.5pt}{brown},
    borderline south={1pt}{-0.5pt}{brown},
    colback=#3,
    colframe=#3,
    colbacktitle=#3,
    fuzzy shadow={0mm}{-3.5pt}{-0.5pt}{0.4mm}{black!60!white},
    overlay={
        \fill [fill=brown] (frame.south west) -- ++(7pt,0) -- ++(0,-5pt) -- cycle;
        \fill [fill=brown] (frame.north west) -- ++(7pt,0) -- ++(0,5pt) -- cycle;
        \fill [fill=brown] (frame.north east) -- ++(-7pt,0) -- ++(0,5pt) -- cycle;
        \fill [fill=brown] (frame.south east) -- ++(-7pt,0) -- ++(0,-5pt) -- cycle;
    },
    after={\vspace{10pt plus 1pt}\noindent},
    #1
}

\begin{document}
\begin{multicols}{2}
\lipsum[1-4]
\end{multicols}
\begin{paperbox}{lipsum}
\lipsum[1-4]
\end{paperbox}
\begin{multicols}{2}
\lipsum[1-4]
\end{multicols}
\end{document}
1

In previous solutions, the text flows from left column to right column before tcolorbox and it continues before the tcolorbox from left to right column. I've nothing to add if this is the desired behaviour. But if you prefer text flowing on left column before and after the tcolorbox and later going to right column, following code shows a partial (manual) solution.

It uses tcolorbox magazine and tcbraster libraries and also multicol instead of twocolumn option.

You should know which part of the text is going to be on the interrupted page and decide how long will be the four text fragments. I decide their sizes by trial and error tests. All this text will be inserted in mybox environment which will fragment it and produce 6 fragments. Later on all these fragments are placed on our paper. The page with the tcolorbox is composed with a tcbraster environment where 4 central fragments are placed.

To distinguish between fragmented text and regular one, I've added a watermark number behind each fragment.

I must say that the final alignment is not perfect, but I don't know how to improve it.

The final composition looks like:

enter image description here

And a detail for the tcolorbox page is:

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\usepackage{multicol}

\newtcolorbox{mybox}[1][]{
    enhanced,
    breakable,
    blanker,
    notitle,
    colback=green!7,
    break at=\pagegoal-\pagetotal-8mm/5cm/10.5cm/5cm/10.5cm/0pt,
    reset box array,
    store to box array,
    watermark text=\arabic{tcbbreakpart},
    width=\linewidth,
    #1
}

\begin{document}
\begin{multicols}{2}
\lipsum[1-3]
\begin{mybox}
\lipsum[4-9]
\end{mybox}
\consumetcboxarray{1}{blanker,before=\par\vfill\noindent}
\end{multicols}
\begin{tcbitemize}[raster columns=2, raster valign=top]
\tcbitem[blanker]\consumeboxarray{2}
\tcbitem[blanker]\consumeboxarray{4}
\tcbitem[raster multicolumn=2, title=A tcolorbox, rounded corners, colframe=black, colback=pink, size=normal]
\lipsum[2]
\tcbitem[blanker]\consumeboxarray{3}
\tcbitem[blanker]\consumeboxarray{5}
\end{tcbitemize}
\begin{multicols}{2}
\consumetcboxarray{6}{blanker,before=\par\vfill\noindent}
\lipsum[10-13]
\end{multicols}
\end{document}

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.