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}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}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}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.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 2025Pitfalls
- Inside
figureandtableuse\centeringand not thecenterenvironment, which adds vertical space to the float. See Center an image in LaTeX and Center a table in LaTeX. - In a table column of type
p{...}, write>{\raggedright\arraybackslash}p{3cm}with thearraypackage.\raggedrightchanges what\\does, and\arraybackslashrestores it as the end of the table row.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
ragged2e - How-to Center a table in LaTeX
- How-to Center an image in LaTeX
- How-to Hyphenation in LaTeX
- How-to Align text in table cells in LaTeX