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.

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%%%%%%%%%%
\usepackage{ulem}

%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
1  
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

1 Answer 1

up vote 5 down vote accepted

Try this:

\dashuline{\hfill This is a test}

A compete example:

\documentclass{article}
\usepackage{ulem}

\begin{document}

\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} 

\end{document}

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

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.