Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I need to create command that underlines some given text that takes several lines. And the underline of the last line should be extended up to the right side of page. When I need just to underline multiline text I use \ul from soul package. But I couldn't find any trick to extend last line. Something like \ul{Last line\hfill\mbox{}} gives nothing. Using \soulregister{\hfill}{0} doesn't help, too. Even if I force line break, \hfill will be ignored, i.e. \ul{Last line\hfill\mbox{}\linebreak} gives line with huge space between Last and line and no space after line. The only way to get something close to desired that I've found is the following.

\documentclass{article}
\usepackage{soul}

\newcommand{\raisedrule}[1]{\leaders\hbox{\rule[#1]{1pt}{0.4pt}}\hfill}
\newcommand{\longunderline}[1]{\ul{#1}\raisedrule{-3.5pt}\mbox{}}
\soulregister{\hfill}{0}

\begin{document}
    \longunderline{Some long text. Some long text. Some long text. Some long text. Some long text. Some long text.}

    \longunderline{Some short text.}

    \ul{Oh, \hfill.}
\end{document}

However height of raise of rule may depend on text and there is some break between underline and rule after text. So my solution is really bad. Do you see something better?

More complex case when I need to make exact number of undelined lines, supposing that text is always short enough to fit into desired number of lines, but not always long enough, i.e. some lines may be completely blank. Any idea?

EDIT

Using ulem and \uline instead of soul and \ul allows to “underline” \hfill. However it gives new problem loosing hyphenation. More interesting that it is possible to “help” it to make hyphen.

\documentclass{article}
\usepackage{soul}
\usepackage{ulem}

\pagestyle{empty}
\soulregister{\hfill}{0}

\begin{document}
    \uline{Some long text. Some long text. Some long text. Some long text. Somelongword. Some long text.\hfill}

    \uline{Some long text. Some long text. Some long text. Some long text. Somelong\-word. Some long text.\hfill}

    \ul{Some long text. Some long text. Some long text. Some long text. Somelongword. Some long text.\hfill}
\end{document}

enter image description here

Middle version is what I want to get, but now it is needed to allow hyphen by hand.

EDIT 2

One more example. Here \uline makes overfull while \ul does not make neither overfull nor underfull.

\documentclass{article}
\usepackage{soul}
\usepackage{ulem}

\begin{document}
    \Huge
    \ul{Some long text. Some long text. Some long text. Some long text. Some long text. Some long text.}

    \uline{Some long text. Some long text. Some long text. Some long text. Some long text. Some long text.}
\end{document}

enter image description here

share|improve this question
    
Although, \ul{...Last Line \hfill something} gives interesting results. –  Sean Allred Oct 12 '13 at 4:32
    
The same as \ul{Oh, \hfill.}. –  Smylic Oct 12 '13 at 4:58

2 Answers 2

up vote 3 down vote accepted
\documentclass{article}
\usepackage{soul}
\usepackage{linegoal}


\newcommand{\raisedrule}[1]{\rule[#1]{\linegoal}{0.45pt}}
\newcommand{\longunderline}[1]{\ul{#1}\raisedrule{-.75ex}}

\begin{document}
    \longunderline{Some long text. Some long text. Some long text. Some long text. Some long text. Some long text.}

    \longunderline{Some short text.}

    \longunderline{Oh,.}

    \longunderline{Last line}

    \longunderline{Some long text. Some long text. Some long text. Some long text. Somelongword. Some long text.}
\end{document}

enter image description here

This takes at least two compilation runs.

share|improve this answer
    
Looks very well, thank you! But how did you get 0.45pt value? It becomes too thin for \Huge font. However \SOUL@ulthickness equals to 0.1ex by default and this value is always good. –  Smylic Oct 13 '13 at 0:32
    
@Smylic hehe. I eye balled. Adjust the values as you need please. Please remember that dimensions in pt will be fixed with font change. Use either in ex or em. –  Harish Kumar Oct 13 '13 at 0:33
    
BTW default line thickness in ulem is 0.4pt. –  Smylic Oct 13 '13 at 0:46
    
@Smylic One can convert ex in to pt and vice versa. There is an answer in the site for that. In fact you can use \SOUL@ulthickness itself so that it changes dynamically. Similarly for raisebox... –  Harish Kumar Oct 13 '13 at 0:49

If you don't mind to use the ulem package instead of soul, this works:

\documentclass{article}
\usepackage[normalem]{ulem}

\newcommand{\longunderline}[1]{\uline{#1\hfill\mbox{}}}

\begin{document}
    \longunderline{Some long text. Some long text. Some long text. Some long text. Some long text. Some long text.}

    \longunderline{Some short text.}

    \longunderline{Oh.}
\end{document} 

Output

enter image description here

share|improve this answer
    
Thank you! I should check it myself. However this solution is not perfect, because it looses hyphenation. See \longunderline{Some long text. Some long text. Some long text. Some long text. Somelongword. Some long text.}. \ul makes hyphen, \uline gives overfull. The most interesting that specifying possible hyphenation by \- makes sense for \uline. –  Smylic Oct 12 '13 at 11:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.