So I am using the multicols
environment and I want to have the background of some portions of the column colored.
However, I see that multicols
does not play well with xcolor
and colored sentences overflow in the next column.
Why is that happening? Would tcolorbox
work better in this case?
Example:
\documentclass[10pt,landscape, fleqn]{article}
\usepackage{multicol}
\usepackage{calc}
\usepackage{ifthen}
\usepackage[landscape]{geometry}
\usepackage{amsmath,amsthm,amsfonts,amssymb}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{graphicx,overpic}
\usepackage{hyperref}
\usepackage{listings}
%problem statement
\newcommand{\problem}[1] {
\rule{1\linewidth}{0.25pt}\\
\colorbox{yellow}{#1}
}
% -----------------------------------------------------------------------
\begin{document}
\raggedright
\footnotesize
\begin{multicols*}{3}
\setlength{\premulticols}{1pt}
\setlength{\postmulticols}{1pt}
\setlength{\multicolsep}{1pt}
\setlength{\columnsep}{2pt}
\problem{This is a long sentence that will unfortunately cross the multicols boundaries.}
This is a long sentence that will not cross the multicols boundaries.
\end{multicols*}
\end{document}
\colorbox
is like\mbox
and produces a box which is by definition unbreakable and does not wrap over the line. This is unrelated to multicols you would see the same in any paragraph.