3

There are many questions/answers on Stack Exchange and elsewhere regarding underlining text in latex. After reading (a selection of) these, I tend to use \underline{...}. I have one (fairly major) complaint.

The vertical spacing changes dependent on ....

Eg, \underline{words} looks fine, while \underline{writings} looks (in my opinion) awful because the line is placed so far below the text, so as to be sufficiently below the g.

With a g, due to the fact that the bit below the line is the full width of the letter, one can get around this with \underline{writin}g\underline{s} (most unsatisfactory). However, something like that doesn't work for p or q.

How can I force the underline to be placed at the natural height below the word (such as in the case \underline{text} for all words? (The line would then pass through parts of a g, p or q.)

Sam OT
  • 1,329
  • 2
    Well, \underline is kind of the roughest way to underline stuff, since it is nothing but a thin wrapper around a plain TeX math-mode macro. Did you look at the packages ulem and soul? They both provide means to set the underline depth manually. The standard definition, however, is the opposite of what you want (the underline will be low also for a word without descenders), but that can be easily changed. – campa Feb 17 '20 at 13:04
  • \underline{words} look also awful, no matther the depth of the line (in my opinion, of course, but not only ... have you seen many books or indexed journals with underlines?) – Fran Feb 17 '20 at 17:04
  • @Fran I didn't feel it was beneficial to the question to add, but it's for a (beamer) presentation. For journal articles, I agree; I wouldn't use underline there, but rather italics :) – Sam OT Feb 17 '20 at 17:12
  • @SamT Although used prudently it does not harm, still make the text harder to read in a presentation. Moreover, In Beamer you can highlight text in more ways than in formal documents, I would rather use \alarm{word}, \structure{word}, \colorbox{yellow}{word}, \spot{word} (package spot), etc. – Fran Feb 17 '20 at 19:11
  • @Fran I am only using it for single definition, but I shall certainly bear your suggestions in mind -- I was not aware of them -- thank you! – Sam OT Feb 17 '20 at 21:23
  • @cgnieder It's certainly very relevant! But no, I don' think it does answer the question fully. Rather, the answer given by Sebastiano below is superior, at the very least for my question :) – Sam OT Jun 20 '20 at 17:22
  • @SamT which is the same as this answer to the linked question: https://tex.stackexchange.com/a/75406/5049 ;) – cgnieder Jun 20 '20 at 17:25
  • Haha, really? Those look significantly more complicated... -- no, I see, myul (not myulline) in the linked answer is the same – Sam OT Jun 20 '20 at 21:13

1 Answers1

9

My answer it has been, only, one very bit modification of this question at this link.

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage{contour}
\usepackage[normalem]{ulem}
\renewcommand{\ULdepth}{1.8pt}
\contourlength{0.8pt}
\newcommand{\myuline}[1]{%
  \uline{\phantom{#1}}%
  \llap{\contour{white}{#1}}%
}

\begin{document} \myuline{writings} in \myuline{plpgpqyy}.

\end{document}

Sebastiano
  • 54,118
  • My only concern is that when you start with a p there is a tiny bit of underline to the left of the stick in the p. Other than that, excellent, thank you. I had actually seen this link before, but obviously hadn't looked carefully. Thank you for redrawing it to my attention! – Sam OT Feb 17 '20 at 14:42
  • I think, with such humility, that the parameters that they have been indicated, have been suitably chosen so that the white character, as an outline to the letters, eliminates just enough to have a correct underlining that is placed behind the p character. I have made several attempts but the result is very bad. Try changing the parameters 1.8 and 0.8 and you'll see the result. You've been very kind. Good work. – Sebastiano Feb 17 '20 at 16:38
  • I think it depends on the font. I was putting this in a beamer document, which uses a sanserif font. I see that in your example above it does not have the artefact I describe. I shall try adjusting the parameters as you suggest! Thank you :) – Sam OT Feb 17 '20 at 16:59
  • @SamT Glad I could help. Thank to you. – Sebastiano Feb 17 '20 at 22:56