Center, left-align and right-align text in LaTeX (center, flushleft, flushright)

LaTeX justifies text by default. The environments center, flushleft and flushright centre a block or set it flush left or flush right. Inside a group, a figure or a table cell, use the switches \centering, \raggedright and \raggedleft.

Preamble

The snippets on this page need these lines before \begin{document}:

\usepackage{ragged2e}

Centre text

The center environment centres every line and adds space above and below the block. \\ ends a line inside it.

\begin{center}
  A centred line\\
  and a second one
\end{center}
Result
The compiled example

Open in the editor

Flush left and flush right

flushleft sets the lines at the left margin with a ragged right edge. flushright sets them at the right margin.

\begin{flushleft}
  This text is set flush left.
\end{flushleft}
\begin{flushright}
  Berlin, 3 May 2025
\end{flushright}
Result
The compiled example

Open in the editor

Switches without extra space

\centering, \raggedright and \raggedleft change the alignment up to the end of the group and add no vertical space. The paragraph has to end inside the group, with \par or an empty line.

{\centering
This paragraph is centred without extra space above or below it.
\par}
Result
The compiled example

Open in the editor

Ragged right with hyphenation

\raggedright from LaTeX hyphenates almost no words, so the right edge becomes very uneven in narrow columns. \RaggedRight from the ragged2e package allows hyphenation. \justifying from the same package switches back to justified text.

\RaggedRight
This paragraph is set ragged right, and long words are still hyphenated
at the end of a line.

\justifying
This paragraph is justified again.
Result
The compiled example

Open in the editor

Left and right in the same line

\hfill is a space that stretches as far as it can. Between two pieces of text it pushes the first to the left margin and the second to the right margin.

\noindent Jane Doe \hfill 3 May 2025
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages