TransWikia.com

Why does underlined text not get wrapped once it hits the end of a line ?

TeX - LaTeX Asked by gabkdlly on July 17, 2021

Sometimes I want to underline some text, and it extends past the end of a line. Why does underline{} not automatically wrap my text for me ?

Also, how can I underline text so that it will still wrap ?

3 Answers

In text mode, the underline command will enclose its argument in a horizontal box, which doesn't allow linebreaks. Use the ul command of the soul package instead.

documentclass[12pt]{article}

usepackage{soul}

begin{document}

A sentence that is just included to fill the line. underline{Some text with underlining.}

A sentence that is just included to fill the line. ul{Some text with underlining.}

end{document}

enter image description here

EDIT: As for why underline works the way it does, see this entry in the UK TeX FAQ for starters. It would seem that Leslie Lamport (the author of LaTeX) implemented just a "quick fix", and that only later package authors came up with more satisfactory solutions for underlining. See sections 2 and 7 of the soul documentation to get an idea of how complicated things are.

Correct answer by lockstep on July 17, 2021

The ul command from the soul package has troubles with Umlauts -- the uline command from the ulem package doesn't and therefore seems to be the better option for those not exclusively writing in English.

Answered by Name on July 17, 2021

If you're using the LuaTeX engine (or can use it) you could use the lua-ul package, that allows underlining without any restrictions on the input (unlike soul) and with fully functioning kerning, hyphenation, etc. (unlike ulem).

documentclass[]{article}

usepackage{lua-ul}

begin{document}
begin{minipage}{3cm} % to show automatic hyphenation works
  underLine
    {%
      This is some text that gets automatically hyphenated
      while being under%
    }lined.
end{minipage}
end{document}

enter image description here

As you can see, hyphenation even works correctly for words not completely inside the argument of underLine.

Answered by Skillmon on July 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP