# Right aligning text while underlining entire line

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?

-
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
add comment

## 1 Answer

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}


Instead of

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


for just one line, using

\hfill\dashuline{This is a test}


is better.

-
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
add comment