# Wraparound of tikz pictures in twocolumn layout

I am currently typesetting a document in a two column layout. Many text blocks are put into colored boxes, currently implemented with TikZ. This works; however, I have to split the text blocks manually between two columns, otherwise the whole column will move to the second column, as the tikzpicture gets too large. Is there any way to automatically split all nodes of a tikzpicture when the bottom of a column is reached? If not, can I implement this using a theorem package?

\documentclass[twocolumn]{scrartcl}
\usepackage{lipsum}
\usepackage{tikz}

\newcommand\mybox[1]{%
\noindent\begin{tikzpicture}%
\node[rectangle, draw=red!40, fill=red!20, inner sep=10pt] (box){%
\begin{minipage}{0.9\columnwidth}%
#1%
\end{minipage}%
};%
\end{tikzpicture}%
}

\begin{document}
\section{Observe overflow:}
\mybox{\lipsum[1]}
\mybox{\lipsum[3]}

\newpage
\section{Correctly set:}
\mybox{\lipsum[4]}

\end{document}

-
Since you are using a minipage, it is not possible to break the box rather use the mdframed package. –  Yiannis Lazarides Oct 10 '11 at 14:06
This answer has a really complicated set of commands for drawing boxes around tikz across multiple pages. With some non-trivial modifications it could be made to work in your case too, I think. I daren't try.... –  Aaron Oct 10 '11 at 14:29

Based on the comment by @Yiannis Lazarides, here is an example of how you could do it with mdframed. You really don't need the TikZ package in this case:

\documentclass[twocolumn]{scrartcl}
\usepackage{lipsum}
\usepackage{mdframed}

\newcommand\mybox[1]{%
%   \minsizebox{0.9\columnwidth}{\textheight}{\parbox{0.9\columnwidth}{#1}}
\begin{mdframed}[linewidth=1pt,linecolor=red!40,backgroundcolor=red!20]
#1
\end{mdframed}
}

\begin{document}
\section{Observe no overflow:}
\mybox{\lipsum[1-3]}

\mybox{\lipsum[3]}

\newpage
\section{Also correctly set:}
\mybox{\lipsum[4]}

\end{document}


The line has three 'layers', which can be tweaked individually (e.g. multicolored line for the frame), etc., as described in the package documentation.

-

TikZ is definitely overkill for this usage, unless you want fancier decorations of your boxes besides background colors and rules.

I tried the mdframed package but I got some extraneous rules and colorboxes that extended into the second column. The package docs say it doesn't work with multicolumn environments.

Here is a sort of solution with the framed package:

\documentclass[twocolumn]{scrartcl}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{framed}

\makeatletter
\newenvironment{MyBox}{%
\colorlet{framecolor}{red!40}%
\setlength{\fboxrule}{2pt}%
\MakeFramed {\FrameRestore\@setminipage}}%
{\par\unskip\endMakeFramed}
\newcommand{\mybox}[1]{\begin{MyBox}#1\end{MyBox}}
\makeatother

\begin{document}
\section{Observe overflow:}
\mybox{\lipsum[1-2]}
\mybox{\lipsum[3]}

\newpage
\section{Correctly set:}
\mybox{\lipsum[4]}

\end{document}


I say "sort of" because I don't think you want one box per paragraph, and this is what happens with this package.

-