# Colorbox does not linebreak

I'm new here, so I'm sorry for any mistakes or error in from my part.

I am trying to make colored textboxes that refer to colored blocks in a figure. My problem is that the colored box does not linebreak at the end of the page.

Does anyone know a way around it?

(I don't know how to make the in-post render of the tex-code, so I'll just attach a screenshot of how it looks like.)

\documentclass[a4paper]{article}
\usepackage{xcolor}

\begin{document}

\colorbox[RGB]{0,209,0}{This block represents a generic three phase back emf, like a power line, as vectors.} \\
\colorbox[RGB]{232,209,82}{This block converts the vectors to three phase representation.} \\
\colorbox[RGB]{255,66,209}{The Modulator that can perform sinus, symmetric or minswitch modulation, with fixed or random carrier wave frequency.} \\
\colorbox[RGB]{97,189,252}{This is an ideal three level inverter.} \\
\colorbox[RGB]{255,128,0}{This is a model of the grid connection and the load. It also calculates how much current is taken from the DC link.}

\end{document}


(I use Texmaker, Miktex, Windows 10)

• Code is never rendered in post here, so any output you see is typically just that: a screenshot. Welcome to the site! – Torbjørn T. Jun 1 '16 at 15:27
• A \colorbox does not wrap, unless using a \parbox, e.g – user31729 Jun 1 '16 at 15:29

colorbox does not wrap automatically, put the text in a \parbox for a example and it will work:

Other ways: Use tcolorbox, for example:

\documentclass[a4paper]{article}
\usepackage{xcolor}

\usepackage{showframe}
\usepackage[skins]{tcolorbox}

\tcbset{commonstyle/.style={boxrule=0pt,sharp corners,enhanced jigsaw,nobeforeafter,boxsep=0pt,left=\fboxsep,right=\fboxsep}}

\newtcolorbox{mycolorbox}[1][]{commonstyle,#1}

\newlength\myboxwidth

\setlength{\myboxwidth}{\dimexpr\textwidth-2\fboxsep}

\begin{document}
\parindent=0em
\colorbox[RGB]{0,209,0}{This block represents a generic three phase back emf, like a power line, as vectors.}

\colorbox[RGB]{232,209,82}{This block converts the vectors to three phase representation.}

\colorbox[RGB]{255,66,209}{The Modulator that can perform sinus, symmetric or minswitch modulation, with fixed or random carrier wave frequency.}

\colorbox[RGB]{97,189,252}{This is an ideal three level inverter.}

\colorbox[RGB]{255,128,0}{This is a model of the grid connection and the load. It also calculates how much current is taken from the DC link.}

\begin{center}
With \verb!\parbox!
\end{center}
\colorbox[RGB]{0,209,0}{\parbox{\myboxwidth}{This block represents a generic three phase back emf, like a power line, as vectors.}}

\colorbox[RGB]{232,209,82}{\parbox{\myboxwidth}{This block converts the vectors to three phase representation.}}

\colorbox[RGB]{255,66,209}{\parbox{\myboxwidth}{The Modulator that can perform sinus, symmetric or minswitch modulation, with fixed or random carrier wave frequency.}}

\colorbox[RGB]{97,189,252}{\parbox{\myboxwidth}{This is an ideal three level inverter.}}

\colorbox[RGB]{255,128,0}{\parbox{\myboxwidth}{This is a model of the grid connection and the load. It also calculates how much current is taken from the DC link.}}

\definecolor{colorone}{RGB}{0,209,0}
\definecolor{colortwo}{RGB}{232,209,82}
\definecolor{colorthree}{RGB}{255,66,209}
\definecolor{colorfour}{RGB}{97,189,252}
\definecolor{colorfive}{RGB}{255,128,0}

\begin{center}
With \texttt{tcolorbox}
\end{center}

\begin{mycolorbox}[colback=colorone]
This block represents a generic three phase back emf, like a power line, as vectors.
\end{mycolorbox}

\begin{mycolorbox}[colback=colortwo]
This block converts the vectors to three phase representation.
\end{mycolorbox}

\begin{mycolorbox}[colback=colorthree]
The Modulator that can perform sinus, symmetric or minswitch modulation, with fixed or random carrier wave frequency.
\end{mycolorbox}

\begin{mycolorbox}[colback=colorfour]
This is an ideal three level inverter.
\end{mycolorbox}

\begin{mycolorbox}[colback=colorfive]
This is a model of the grid connection and the load. It also calculates how much current is taken from the DC link.
\end{mycolorbox}

\begin{center}
\end{center}

This block represents a generic three phase back emf, like a power line, as vectors.
\end{mycolorbox}

\end{document}


You can use soul:

\documentclass[a4paper]{article}
\usepackage{soul}
\usepackage{xcolor}

\newcommand{\ctext}[3][RGB]{%
\begingroup
\definecolor{hlcolor}{#1}{#2}\sethlcolor{hlcolor}%
\hl{#3}%
\endgroup
}

\begin{document}

\noindent
\ctext[RGB]{0,209,0}{This block represents a generic three phase back emf, like a power line, as vectors.} \\
\ctext[RGB]{232,209,82}{This block converts the vectors to three phase representation.} \\
\ctext[RGB]{255,66,209}{The Modulator that can perform sinus, symmetric or minswitch modulation, with fixed or random carrier wave frequency.} \\
\ctext[RGB]{97,189,252}{This is an ideal three level inverter.} \\
\ctext[RGB]{255,128,0}{This is a model of the grid connection and the load. It also calculates how much current is taken from the DC link.}

\end{document}