Text FormattingHighlighting text

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
TobiTuberkel
Posts: 1
Joined: Sat Nov 06, 2010 11:44 am

Highlighting text

Post by TobiTuberkel »

I'm trying to highlight text (which can be anything from a single word to whole sentences/passages) using the soul and color packages.

This works fine except that certain characters (e.g. lower case 'f's) get "cut off" in a peculiar way. Here's an example...

Code: Select all

\documentclass{article}
\usepackage{color,soul}
\definecolor{lightgray}{gray}{0.85}
\sethlcolor{lightgray}
\begin{document}
\hl{aaa aaf faa aaa}\par
\hl{\textit{aaa aaf faa aaa}}
\end{document}
Any idea how this may be rectified?
Thanks, T

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

php1ic
Posts: 192
Joined: Wed Jan 28, 2009 8:17 pm

Highlighting text

Post by php1ic »

Looks like each word is created and positioned individually with the background colour. The "f" character is too wide so is covered by the background of the next word.

Add a small space to words that end with an "f"

Code: Select all

\documentclass{article}
\usepackage{color,soul}
\definecolor{lightgray}{gray}{0.85}
\sethlcolor{lightgray}
\begin{document}
\hl{aaa aaf faa aaa}\par
\hl{\textit{aaa aaf faa aaa}}

\hl{aaa aaf\, faa aaa}\par
\hl{\textit{aaa aaf\, faa aaa}}
\end{document}
Or just use a colorbox

Code: Select all

\documentclass{article}

\usepackage{color}

\definecolor{light-gray}{gray}{0.85}

\begin{document}
\colorbox{light-gray}{aaa aaf faa aaa}
\end{document}
Post Reply