![为什么使用 \colorbox 后段落会变成一行长线?](https://linux22.com/image/358573/%E4%B8%BA%E4%BB%80%E4%B9%88%E4%BD%BF%E7%94%A8%20%5Ccolorbox%20%E5%90%8E%E6%AE%B5%E8%90%BD%E4%BC%9A%E5%8F%98%E6%88%90%E4%B8%80%E8%A1%8C%E9%95%BF%E7%BA%BF%EF%BC%9F.png)
如上图所示,当使用颜色突出显示文本时,我们会失去段落格式,所有文本都会变成一行。如果段落足够长,其余文本甚至会超出边距。我该如何解决这个问题,让文本保持正常格式(即实际段落)但突出显示?我的源代码:
\documentclass{IEEEtran}
\usepackage{blindtext}
\usepackage[svgnames]{xcolor}
\begin{document}
\Large
\colorbox{SkyBlue}{The text in colored box overlaps with neighboring column as seen here}
\normalsize
\Blindtext
\end{document}
答案1
在 LaTeX 中使用soul
包 (load xcolor
before soul
)。
\documentclass{article}
\usepackage{multicol}
\usepackage{blindtext}
\usepackage{xcolor}
\usepackage{soul}
\begin{document}
\begin{multicols}{2}
\hl{The text in colored box overlaps with neighboring column as seen here}
\blindtext
\end{multicols}
\end{document}
答案2
在 ConTeXt MKIV 中这非常简单。
% https://randomdeterminism.wordpress.com/2010/10/31/can-i-borrow-your-highlighter-please/
\definebar
[highlight]
[order=background,
rulethickness=2.5,
offset=1.25,
continue=yes,
color=yellow]
\starttext
\startcolumns[n=2]
\highlight{The text in colored box overlaps with neighboring column as seen here}
\input lorem
\stopcolumns
\stoptext