# Underline width

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?

• Are you wishing to use the native \underline macro, or are you open to other solutions that don't use packages? Does it need to line break? If yes, does it need to hyphenate? – Steven B. Segletes Jul 27 '18 at 14:46
• @StevenB.Segletes: Although I prefer to use '\underline' macro, but other suggestions are welcomed. No it dose not need any line break. – Astrolabe Jul 27 '18 at 14:54

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.

\documentclass{article}
\usepackage{lipsum}
\newcommand\dunderline[3][-1pt]{{%
\setbox0=\hbox{#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}


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}


• Should you wrap the \ooalign in a group, perhaps? It sets \lineskiplimit=-\maxdimen, after all. – Harald Hanche-Olsen Jul 27 '18 at 16:52
• @HaraldHanche-Olsen I didn't know that, so thank you, I will edit. Without it, the dunderline can interfere with what is below. – Steven B. Segletes Jul 27 '18 at 17:02

Of course, soul allows line breaks in underlined material. If you want it, then use soul. But you should avoid underlining altogether.

Otherwise, here's a version that is customizable like for \setul.

\documentclass{article}

\newlength{\myuldp}
\newlength{\myulthickness}
\newcommand{\setmyul}[2]{%
\if\relax\detokenize{#1}\relax\else
\setlength{\myuldp}{#1}%
\fi
\setlength{\myulthickness}{#2}%
}
\newcommand{\setmyuldepth}[1]{%
\settodepth{\myuldp}{%
\if\relax\detokenize{#1}\relax\myulalphabet\else#1\fi
}%
}
\newcommand{\myulalphabet}{abcdefghijklmnopqrstuvwxyz}
\newcommand{\myulline}{%
height -\myuldp
depth \dimexpr\myuldp+\myulthickness
\hfil
}
% initialize
\setmyul{0pt}{0.4pt}
\setmyuldepth{}
%%%

\newcommand{\myul}[1]{{\ooalign{#1\cr\myulline\cr}}}

\begin{document}

\myul{Abcdefghi} \myul{abcyj}

\setmyul{}{2pt}

\myul{Abcdefghi} \myul{abcyj}

\setmyul{1pt}{0.4pt}

\myul{Abcdefghi} \myul{abcyj}

\end{document}


An empty argument in \setmyuldepth uses the whole lowercase alphabet to decide the depth; an empty first argument to \setmyul means “don't change the current value”.