TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For the record, I've spent about five hours endlessly looking here and elsewhere on the Internet, looking for an answer.

I'm relatively new to using LaTeX and am trying to create right aligned text that is underlined, but the underline spans the entire length of the line. I've spent several hours on this and this is the closest I've gotten

To demonstrate the problem I've run into, I created this example:

%%%%%%%%%%Begin example%%%%%%%%%%

%This creates a dashed underline
\dashuline{This is a test}

%This right align our dashed underlined text
\raggedleft\dashuline{This is a test} 

%This creates a dashed underline that spans the entire line
\dashuline{This is a test\hspace*{\fill}} 

%This should create a dash underline that spans the entire line and right aligns our text, 
%but the text ends up left aligned. Why is this?
\raggedleft\dashuline{This is a test\hspace*{\fill}} 

%%%%%%%%%%%End example%%%%%%%%%%%%%%

As far as I can tell, something to do with the \hspace*{\fill} is causing this, since everything works just fine, sans underlining the entire line. Is there a way to fix this or another way to accomplish this that will work?

share|improve this question
You are adding the fill on the wrong side – Peter Grill Oct 13 '12 at 19:32
Welcome to TeX.sx! – Kurt Oct 13 '12 at 19:52
up vote 6 down vote accepted

Try this:

\dashuline{\hfill This is a test}

A compete example:



\noindent\dashuline{This is a test}

{\raggedleft\dashuline{This is a test}\par} 

\noindent\dashuline{This is a test\hspace*{\fill}} 

\noindent\dashuline{\hfill This is a test} 


enter image description here

Instead of

{\raggedleft\dashuline{This is a test}\par} 

for just one line, using

\hfill\dashuline{This is a test}

is better.

share|improve this answer
I'm not exactly sure why this works, but this is exactly what I was trying to do. Thanks. – BinaryMan Oct 13 '12 at 20:12
@BinaryMan if you feel more comfortable using \hspace*{\fill}, you can say \dashuline{\hspace*{\fill}This is a test} instead of using \hfill. – Gonzalo Medina Oct 13 '12 at 20:19
Very helpful, thank you! – Limited Atonement May 29 '15 at 20:02

Your Answer


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.