LaTeX has no right-align button in the usual sense. Instead, you use fill commands, which stretch to take up the spare space on a line. The two most useful are \hfill, which leaves a gap that pushes text to the right, and \dotfill, which fills the gap with dots.
Right-align one piece of text with \hfill
Put \hfill before the text you want on the right edge of the line. Start the line with \noindent if you do not want the paragraph indent:
\noindent\hfill Berlin, 22 November 2026
The \hfill command is stretchable space. It takes up whatever room is left on the line, so the text after it sits at the right margin. The stretch only works on a single line. If the text wraps, the part after the break moves to the next line, where the fill has no effect.
Left and right text on the same line
Place \hfill between two pieces of text to push one to the left edge and the other to the right edge:
Department of Physics\hfill Room 204
Right-align a paragraph or block
To right-align several lines, use the flushright environment. Line breaks inside it are written with \\:
\begin{flushright}
Berlin, 22 November 2026\\
Department of Physics
\end{flushright}
For a passage inside a group, use the \raggedleft declaration instead. It applies until the end of the group, so wrap the passage in braces:
{\raggedleft
This paragraph is set flush right.\par}
Dot leaders with \dotfill
\dotfill works like \hfill, but it fills the space with dots:
Introduction\dotfill 1
This prints “Introduction” followed by dots and the page number “1” at the right margin. As with \hfill, the dots only appear where there is spare room on the line.
Setting a fixed length for a dot leader
\dotfill has no length of its own. It stretches to fill whatever space is left, so the leader’s length depends on the line. To fix the length, place \dotfill inside a box of the width you want, using \makebox:
Introduction\makebox[6cm]{\dotfill}1
The box is always 6 cm wide, and the dots fill it exactly. The text after the box (the page number) starts at the box’s right edge. The command \hbox to 6cm{\dotfill} does the same job.
Other fill commands
Two more commands are useful alongside these:
\hrulefilldraws a solid line instead of dots, which suits a form field:Name:\hrulefill\hspace*{\fill}inserts stretchable space that is kept even at the start of a line. The star stops LaTeX from removing it there.
Frequently asked questions
How do I make my text align?
LaTeX offers four alignments: justified (the default for most document classes), left (ragged right), right (ragged left), and centered. Use \raggedright, \raggedleft, or \centering, or the matching flushleft, flushright, or center environments. For a discussion of which alignment to pick for body text, see is it better to align left or justify.
How to right align in LaTeX?
For one line, put \hfill before the text. For a block of text, use the flushright environment or \raggedleft.
How to align left and right on the same line?
Put \hfill between the two pieces of text:
Left text\hfill Right text
The left text stays at the left margin, and the right text sits at the right margin.