The ulem package significantly improves the capabilities of underlining in LaTeX. If you've ever tried to underline an entire paragraph using the normal underline command, you may have noticed that it's not as straightforward. When using the standard underline command, the text within the braces is written on a single line. If the text exceeds one line, it extends beyond the page margin. Not only does this result in an undesired outcome, but it also doesn't generate an error message; instead, it issues a warning.
The example demonstrates what happens when you attempt to underline a whole paragraph in LaTeX using the underline command. However, with the uline command from the ulem package, it works flawlessly.
The ulem package does not require additional packages to be included. It can be included in the document as follows:
\usepackage{ulem}
The package theoretically offers four options: normalem, ULforem, normalbf, and UWforbf.
\emph{Text}
and \em
to their usual behavior, making the text italic.\emph{Text}
and \em
no longer italicize the text; instead, the text is displayed underlined.\textbf{Text}
and \bf
no longer make the text bold; instead, it is underlined.The package provides seven commands, which work in both text and math environments. However, it's important to note that the \sout
command, which strikes through text in the text environment, underlines text in the math environment.
Command | Output |
---|---|
\uline{simple underline} | Simple underline |
\uuline{double underline} | Double underline |
\uwave{wave underline} | Wave underline |
\sout{strike through} | Strike through |
$\sout{strike through?}$ | Strike through? |
\xout{cross out} | Cross out |
\dashuline{dashed underline} | Dashed underline |
\dotuline{dotted underline} | Dotted underline |
The package also provides instructions on how users can create custom commands. Depending on the symbol, it may be necessary to adjust the height using a Raisebox. Note: The \textbrokenbar
command requires the textcomp package to be included (\usepackage{textcomp}
).
\newcommand\cmd{\bgroup \markoverwith{}\ULon} \newcommand\sterne{\bgroup \markoverwith{\raisebox{-2mm}{\textasteriskcentered}}\ULon} \newcommand\broken{\bgroup \markoverwith{\textbrokenbar}\ULon} \newcommand\zensur{\bgroup \markoverwith{\textasteriskcentered}\ULon} \sterne{Underline with stars} \broken{Vertical strike through} \zensur{Cover with stars}
Another package that deals with underlining and striking through text is the Soul package. In addition to underlining and striking through, it also offers simple color usage.