1

I would like to have a colored line. I tried the following:

\documentclass[11pt,english]{article}
\usepackage[T1]{fontenc}
\usepackage[parfill]{parskip}
\usepackage{color,soul}
\setulcolor{red}

\begin{document}

This word is underlined in black: \underline{Zukunft}\\
This word is underlined in red: \ul{Zukunft}


This word is underlined in black: \underline{Gelegenheit}\\
This word is underlined in red: \ul{Gelegenheit}

\end{document}

The output is:

enter image description here

As one can see, the vertical spacing between the underlined word and the underline has increased when underlining the word "Zukunft" in red in comparison to one the underlined in black. Whereas, this is not the case with the word "Gelegenheit". Is this normal? If not, how to have a colored underline without compromising the default LaTeX settings?

1

This is a design choice by soul: it sets a fixed underline depth based on all of the characters in the font, which then takes into account the characters with descenders (like gjpqy).

You can see the compromise in the other direction if you put two words side by side with \underline, then the underlining itself doesn't line up. (Example 1) This is an aesthetic choice, fundamentally. With the soul underlining the underlining of such adjacent words is uniform (Example 2).

You can change the depth of the soul underline using the \setuldepth command to match the height of words without descenders, but then you'd need to change it back to deal with words with descenders. (Example 3). A simple way to make this work is to define a macro to set the depth according to the content every time. (Example 4).

\documentclass{article}
\usepackage{soul}
\usepackage{xcolor}
\usepackage{calc}
\newcommand{\myul}[1]{\setuldepth{#1}\ul{#1}}
\setulcolor{red}
\begin{document}

\begin{enumerate}
\item \underline{abcdef}\underline{gjpqy}
\item \ul{abcdef}\ul{gjpqy}
\item \setuldepth{abc}\ul{abcdef}\ul{gjpqy}
\item \myul{abcdef}\myul{gjpqy}
\end{enumerate}

\end{document}

output of code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.