I have a large number of documents I need to create, and there is one very particular need I cannot find a solution for.

In these documents, there are pieces of text that are underlined and they must be labelled with a number or letter, placed in the middle of the text immediately below the underline.

To do this for short pieces of text, I was using the \underset in math mode with the \ul command from the soul package to do what I needed. This only worked if the items were short and did not go over line breaks.

I know the \ul command by itself handles line breaks well, but I cannot think of how to get this centered label to work across multiple lines. I need the label to appear below the center of the text on each line of the underlined portion.

For example, if I have an underlined sentences labeled "4" that is three lines on paper, it must have the number "4" appearing below the underlined portion on each of the three lines on the page. In particular, if the underlined portion only has a small piece, such as a single word, on one of the lines it appears in, then the label must be centered below that underlined portion, not centered under the whole line in which it appears.

I know this is a complicated request, but I hope one of you brilliant folks has a solution for me to do this in latex (or context if there is only a way to do it there).

Any suggestions are appreciated.

\documentclass[two column]{article}


$\underset{4}{\text{\ul{This is short text}}}$

$\underset{5}{\text{\ul{Much longer text in this format will not split properly along lines, which is the effect I would like to produce.}}}$

\ul{But if I only use the ul command, I will not get the propery labelling on each line like I want}. 


$\underset{6}{\text{\ul{I want something to look like this text does, but I}}}$ \\
$\underset{6}{\text{\ul{don't want to manually break lines.}}}$ More text here.

  • 1
    It is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it and give them a starting point. Feb 21, 2012 at 23:00
  • I wish i could, but i have no idea where to begin on this. I don't have a working example on any level Feb 21, 2012 at 23:04
  • 1
    A working example does not mean one that solves the problem, but rather one that compiles and illustrates the undesired result. It is easier to see the problem rather than try to figure out what you mean in your description. This will also ensure that the solution works for your intended situation. Feb 22, 2012 at 0:31
  • 1
    ok i added an example, i hope it summarizes what i said in the post Feb 22, 2012 at 1:42

2 Answers 2


I've just released soulpos, which allows this with a different approach based on savepos (pdftex or compatible required). Two passes are required:

\documentclass[two column]{article}




\ulnum{4}{This is short text}

\ulnum{6}{I want something to look like this text does, but I
don't want to manually break lines.} More. \ulnum{7}{And more text here.}


soulpos and numbered underlines

  • wow, this is insanely helpful, exactly what i wanted. thanks for this amazing package! Feb 29, 2012 at 8:01
  • Yes a +1 from me as well (even though you just stole my green "accept" tick:-) Feb 29, 2012 at 9:14
  • What's amazing is soul. Feb 29, 2012 at 15:18

enter image description here

Far from perfect, but it's a start. This version doesn't work if start and end are on same line, and doesn't work if a page break happens between them. Both would be fixable.

I looked at this the other day but couldn't remember the trick to measure the position of a point along the line, then by coincidence @FrankMittelbach popped up and gave a full account of it here

How do you change indentation in the middle of a paragraph?

So here's that same code, re-arranged a bit to produce the image above (plain TeX in this version)



\hbox to \hsize{\hskip\lastlinewidth
\leaders\hrule height 0pt depth 1pt\hskip 0pt plus 2fill

\unskip\hbox to \hsize{%
\advance\count0 -1
\hbox to \hsize{%
\leaders\hrule height 0pt depth 1pt\hskip 0pt plus 2fill
\hbox to \lastlinewidth{%
\leaders\hrule height 0pt depth 1pt\hskip 0pt plus 2fill

  \belowdisplayskip=0pt %-\baselineskip
  \belowdisplayshortskip=0pt %-\baselineskip
\global\advance\lastlinewidth by -2em

\def\n{One two thr\-ee four five six seven eight nine ten. }
\def\c{Red blue yellow green. }

\n\c\ustart{3}start underline \n\n
\n\n end underline\uend{3} first text after end

\n\n\n\n\c\ustart{4}start again\c\n\n\c\c\n
\n\n\n end underline\uend{4} first text after end

  • i need to go through this carefully, but this looks like i can definitely tweak this to work for what i need. thanks for the help! Feb 23, 2012 at 0:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .