Colorbox 不换行

Colorbox 不换行

我是新来的,因此对于我所犯的任何错误或失误我深感抱歉。

我正在尝试制作引用图形中彩色块的彩色文本框。我的问题是彩色框在页面末尾没有换行。

有人知道解决这个问题的方法吗?

(我不知道如何进行 tex 代码的后期渲染,因此我仅附上其样子的截图。)

\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}

在此处输入图片描述

(我使用 Texmaker、Miktex、Windows 10)

答案1

您可以使用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}

在此处输入图片描述

答案2

colorbox不会自动换行,将文本放在例如中\parbox,它就会起作用:

其他方式:使用tcolorbox,例如:

\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}
With \texttt{tcolorbox} and shadows.
\end{center}

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

\end{document}

在此处输入图片描述

答案3

如果有人正在使用 luatex 并且偶然发现了这个soul包,那么可以使用这个包轻松替代lua-ul

\documentclass[a4paper]{article} 
\usepackage{xcolor} 
\usepackage{luacolor,lua-ul} %for usage of style attributes - background color

\begin{document}

\highLight[{[RGB]{0,209,0}}]{This block represents a generic three phase back emf, like a power line, as vectors.} \\
\highLight[{[RGB]{232,209,82}}]{This block converts the vectors to three phase representation.} \\
\highLight[{[RGB]{255,66,209}}]{The Modulator that can perform sinus, symmetric or minswitch modulation, with fixed or random carrier wave frequency.} \\
\highLight[{[RGB]{97,189,252}}]{This is an ideal three level inverter.} \\
\highLight[{[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}

结果相同。为了完整性,我添加了这个附加选项。 结果

答案4

也许您可以使用\hl该包soul,不会出现像使用那样的错误\colorbox

以下是一个例子:

\documentclass[11pt]{article}

\usepackage{color,soul}


\begin{document}

\hl{This is a highlight, we can make a very long sentence more than one line, but the highlight result is also very good.}


\end{document}

以下是我整理的结果:

在此处输入图片描述

在此处输入图片描述

相关内容