使用 ulem 包突出显示文本

使用 ulem 包突出显示文本

考虑以下最小示例(取自这个答案):

\documentclass{article}
\usepackage{color}
\usepackage{ulem}
\newcommand\hl{\bgroup\markoverwith
  {\textcolor{yellow}{\rule[-.5ex]{2pt}{2.5ex}}}\ULon}
\begin{document}
This is a test \hl{Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.} text.
\end{document}

如果仔细查看输出,您会发现颜色覆盖了一些字母的一小部分。如何修复此问题?

以下是输出的屏幕截图:

在此处输入图片描述

答案1

一个可能的解决方案是使用\rule宽度较小的;例如

\newcommand\hl{\bgroup\markoverwith
  {\textcolor{yellow}{\rule[-.5ex]{1pt}{2.5ex}}}\ULon}

然而仍然有颜色覆盖了字母 f。

经过 Steven Segletes 的编辑:

由于答题者有一段时间没有登录,我将进一步编辑答案。答案是正确的,但必须进一步缩小宽度,比如说0.1pt。以下是克服问题字母的结果:

\documentclass{article}
\usepackage{color}
\usepackage{ulem}
\newcommand\hl{\bgroup\markoverwith
  {\textcolor{yellow}{\rule[-.5ex]{.1pt}{2.5ex}}}\ULon}
\begin{document}
This is a test \hl{Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.} text.
\end{document}

在此处输入图片描述

但是, 可能仍然存在一个小问题f,它会突出到其边界框的右侧:

在此处输入图片描述

相关内容