75

I have done some search for margin alignment in Latex but cannot find how can I right-align any single line?

For example, in a letter sometimes we put a Sincerely on the right. But without using specific documentclass, how can I align any single line in a paragraph to the right in any documentclass?

Many thanks for the help!

2
  • 7
    Have you tested with \rightline{text}?
    – skpblack
    Commented Aug 11, 2014 at 4:06
  • 1
    Have you looked into using \raggedleft?
    – Mico
    Commented Aug 11, 2014 at 4:35

4 Answers 4

92

Like this?

\documentclass{article}
\usepackage{kantlipsum}
\begin{document}
\kant[1]

\hspace*{\fill} Yours sincerely

This is some more text

\null\hfill Yours sincerely

Again some dummy text

\hspace*{0pt}\hfill Yours sincerely

And again Phew

\mbox{}\hfill Yours sincerely
\end{document}

enter image description here

3
  • The way you write your answer might induce the idea that \par is necessary. I'd simply propose the <blank line> \hspace*{\fill} <text> solution.
    – egreg
    Commented Aug 11, 2014 at 9:13
  • @egreg Oh! Sorry. I wanted it to be a new line and I preferred \par over `\\` I changed it. Thanks.
    – user11232
    Commented Aug 11, 2014 at 9:15
  • 4
    Can you clarify which of these options is the most appropriate in various situations? Or are they all identical? Commented Mar 16, 2020 at 1:40
44

For a short line (With lenght less than \linewidth) you can use \rightline{word or phrase}.

If you want to align a paragraph at right put it in a flushright environment. This way allows line breaks with \\.

\begin{flushright}
Text\\
aligned to\\
the right.
\end{flushright}
13

The simpler solution to right align a line is this:

\documentclass{article}
\begin{document}

Here comes some text.
Have a nice day.

\rightline{Yours sincerely}

\end{document}
1
  • 1
    This is a neat solution (thanks!). I wonder why it has not gotten many upvotes.
    – psyguy
    Commented Sep 13, 2022 at 14:20
6

This will work if the right-aligned content is considered a separate paragraph (i.e., it will have \parskip separation). Note that it will have less vertical separation than a flushright environment.

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\lipsum[4]
{\raggedleft Sincerely,\par}
\lipsum[4]
\end{document}

You must log in to answer this question.

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