更改背景颜色,无需新段落且跨环境

更改背景颜色,无需新段落且跨环境

{\color }可以做到这一点,但仅限于文本颜色。我希望背景也能如此。我看过很多解决方案,但它们要么不能跨环境(例如colorbox)要么不能创建新段落(例如framed)。

我只想突出显示文本的任意区域,而不对它们进行任何其他修改。

编辑: 以 gigi 为例:

\documentclass{article}

\usepackage{color,soul}
\sethlcolor{red}
\begin{document}


text \hl{
\begin{itemize}
        \item text
\end{itemize}
} text

\end{document}

它产生:

$ pdflatex a.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./a.tex
LaTeX2e <2017-04-15>
Babel <3.18> and hyphenation patterns for 84 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/graphics/color.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def))
(/usr/share/texlive/texmf-dist/tex/latex/soul/soul.sty) (./a.aux)
(/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
)

! LaTeX Error: Environment {itemize} undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.12 }
       text
?

答案1

soul包可以执行以下操作:

\documentclass{article}

\usepackage{color,soul}
\sethlcolor{red}
\begin{document}


text \hl{text} text

\end{document}

相关内容