[Tex/LaTex] Underline width

soulunderline

It seems, by using the command \setul{}{ pt} in the soul package, we can change the underline width. But I don't want to use this package. Is there any other command for changing the underline width to an arbitrary size, without using any specific package?

Best Answer

REVISED APPROACH

Here is \dunderline[<offset of line top>]{<thickness>}{<content>}.

EDIT: I took Harald's suggestion to place the macro inside of a group, since \ooalign changes \lineskiplimit. Without the extra group, the underline can run into the content below on the next line. With the extra group, as shown in the MWE, extra vertical space is inserted to prevent overlap.

EDITED to use egreg's suggestion of \sbox0{}, rather than \setbox0=\hbox{}.

\documentclass{article}
\usepackage{lipsum,xcolor}
\newcommand\dunderline[3][-1pt]{{%
  \sbox0{#3}%
  \ooalign{\copy0\cr\rule[\dimexpr#1-#2\relax]{\wd0}{#2}}}}
\begin{document}
\dunderline{1pt}{This is a test}

\dunderline{2pt}{This is a test}

\dunderline[-.5pt]{2pt}{This is a test}

\dunderline[-6pt]{2pt}{This is a test} \lipsum[1]
\end{document}

enter image description here

ORIGINAL OFFERING

The magnification is arbitrary, but only between 1x and 2x the original thickness. It performs the result with a double underline. Since an underline is .4pt thick, the 1st parameter offset can only vary between 0pt (1x mag) to .4pt (2x mag).

\documentclass{article}
\newcommand\dunderline[2][.4pt]{%
  \raisebox{-#1}{\underline{\raisebox{#1}{\smash{\underline{#2}}}}}}
\begin{document}
\underline{This is a normal thickness}

\dunderline[.2pt]{This is 1.5x thickness}

\dunderline{This is 2x thickness}

\end{document}

enter image description here