[Tex/LaTex] Colorbox does not linebreak

colorcolorboxline-breaking

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}

enter image description here

(I use Texmaker, Miktex, Windows 10)

Best Answer

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}

enter image description here

Related Question