Text alignment
Text alignment can be manually controlled by several commands. In this article is explained how to change text justification for either part of the text, or the entire document.
Introduction
LaTeX default text is fully-justified, but often left-justified text may be a more suitable format. This left-alignment can be easily accomplished by importing the ragged2e package.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[document]{ragged2e}
\begin{document}
\section{Heading on Level 1 (section)}
Hello, here is some text without a meaning. This text should shows
what a printed text will look like at this place. If you read this
text, you will get no information...
\end{document}
The line
\usepackage[document]{ragged2e}
imports the package ragged2e and left-justifies the text. See the next section for more information on how this package actually works.
Using the package ragged2e
There are several standard LaTeX commands to change the text alignment. Alternatively, you can use the commands provided by the package ragged2e.
When the text is not fully justified, sometimes it may look "too ragged". The package ragged2e tackles this problem by allowing hyphenation when a line is too short, generating a more uniformly ragged text edge. Below, the example shown at the introduction is compared with an image of the same text left-justified using standard LaTeX commands.
The package provides alternative commands for left justified text, right-justified text and centred text that support hyphenation. For these commands to be available the package has to be imported first, by adding to the preamble the next line:
\usepackage{ragged2e}
Alternative examples to those described in this article are presented in the next link:
Open an example of the ragged2e package in Overleaf
Left-justified text
The default environment for left-alignment is flushleft
\begin{flushleft}
Hello, here is some text without a meaning. This text should show what
a printed text will look like at this place. If you read this text,
you will get no information. Really? Is there no information? Is there
a difference between this text and some nonsense like not at all! A
blind text like this gives you information about the selected font, how
the letters are written and an impression of the look. This text should
contain all letters of the alphabet and it should be written in of the
original language.There is no need for special content, but the length of
words should match the language.
\end{flushleft}
This is the second paragraph. Hello, here is some text without
a meaning. This text should show what
a printed text will look like at this place. If you read this text,
you will get no information. Really? Is there no information? Is there
a difference between this text and some nonsense like not at all! A
blind text like this gives you information about the selected font, how
the letters are written and an impression of the look. This text should
contain all letters of the alphabet and it should be written in of the
original language.There is no need for special content, but the length of
words should match the language.
All the text in between \begin{flushleft}
and \end{flushleft}
is left-justified. The corresponding environment in ragged2e is FlushLeft
.
The switch command \raggedright
will also produce left-aligned text, but the behaviour is different; in this case the text will be left-aligned from the point where the command is declared till another switch command is used. This is more suitable to align long blocks of text or the whole document. The equivalent command in ragged2e is \RaggedRight
.
Right-justified text
Right-aligning text is straightforward with the environment \flushright
.
\begin{flushright}
Hello, here is some text without a meaning. This text should show what
a printed text will look like at this place. If you read this text,
you will get no information. Really? Is there no information? Is there
a difference between this text and some nonsense like not at all! A
blind text like this gives you information about the selected font, how
the letters are written and an impression of the look. This text should
contain all letters of the alphabet and it should be written in of the
original language.There is no need for special content, but the length of
words should match the language.
\end{flushright}
This is the second paragraph. Hello, here is some text without
a meaning. This text should show what
a printed text will look like at this place. If you read this text,
you will get no information. Really? Is there no information? Is there
a difference between this text and some nonsense like not at all! A
blind text like this gives you information about the selected font, how
the letters are written and an impression of the look. This text should
contain all letters of the alphabet and it should be written in of the
original language.There is no need for special content, but the length of
words should match the language.
Text in between \begin{flushright}
and \end{flushright}
is right-justified. If you prefer ragged2e the corresponding environment in that package is FlushRight
.
The switch command \raggedleft
will also produce right-aligned text, but the behaviour is different; in this case the text will be right-aligned from the point where the command is declared till another switch command is used. This is more suitable for large blocks of text or for the whole document. The equivalent command in ragged2e is \RaggedLeft
.
Centred text
To centre a block of text use the environment \center
\begin{center}
Hello, here is some text without a meaning. This text should show what
a printed text will look like at this place. If you read this text,
you will get no information. Really? Is there no information? Is there
a difference between this text and some nonsense like not at all! A
blind text like this gives you information about the selected font, how
the letters are written and an impression of the look. This text should
contain all letters of the alphabet and it should be written in of the
original language.There is no need for special content, but the length of
words should match the language.
\end{center}
This is the second paragraph. Hello, here is some text without
a meaning. This text should show what
a printed text will look like at this place. If you read this text,
you will get no information. Really? Is there no information? Is there
a difference between this text and some nonsense like not at all! A
blind text like this gives you information about the selected font, how
the letters are written and an impression of the look. This text should
contain all letters of the alphabet and it should be written in of the
original language.There is no need for special content, but the length of
words should match the language.
Text in between \begin{center}
and \end{center}
is centred. The corresponding environment in ragged2e is Center
.
The switch command \centering
will also produce centred text, but the behaviour is different; in this case the text will be centred from the point where the command is declared till another switch command is used. This is more suitable for large blocks of text or for the whole document. The equivalent command in ragged2e is \Centering
.
Fully justified text
In LaTeX text is fully-justified by default and if a switch command such as \raggedright
or \raggedleft
is used the text alignment can not be switched back. For this case scenario you can use the package ragged2e. Import it adding \usepackage{ragged2e}
to the preamble, then use the command justify
as shown in the example below.
\centering
Hello, here is some text without a meaning. This text should show what
a printed text will look like at this place. If you read this text,
you will get no information. Really? Is there no information? Is there
a difference between this text and some nonsense like not at all! A
blind text like this gives you information about the selected font, how
the letters are written and an impression of the look. This text should
contain all letters of the alphabet and it should be written in of the
original language.There is no need for special content, but the length of
words should match the language.
\justify
This is the second paragraph. Hello, here is some text without
a meaning. This text should show what
a printed text will look like at this place. If you read this text,
you will get no information. Really? Is there no information? Is there
a difference between this text and some nonsense like not at all! A
blind text like this gives you information about the selected font, how
the letters are written and an impression of the look. This text should
contain all letters of the alphabet and it should be written in of the
original language.There is no need for special content, but the length of
words should match the language.
The first paragraph in the previous example is centred by \centering
and then the alignment is switched back to fully-justified text with \justify
.
ragged2e also provides the environment justify
to fully-justify small blocks of text in a document that is entirely left or right aligned.
Open an example of the ragged2e package in Overleaf
Reference guide
Summary of environments and commands for text alignment
Alignment | Environment | Switch command | ragged2e environment | ragged2e switch command |
---|---|---|---|---|
Left | flushleft
|
\raggedright
|
FlushLeft
|
\RaggedRight
|
Right | flushright
|
\raggedleft
|
FlushRight
|
\RaggedLeft
|
Centre | center
|
\centering
|
Center
|
\Centering
|
Fully justified | justify
|
\justify
|
Open an example of the ragged2e package in Overleaf
Further reading
For more information see :
- Paragraphs and new lines
- Paragraph formatting
- Bold, italics and underlining
- Font sizes, families, and styles
- Font typefaces
- Supporting modern fonts with XeLaTeX
- Line breaks and blank spaces
- Lists
- Sections and chapters
- Multiple columns
- Single sided and double sided documents
- The not so short introduction to LaTeX2ε
- The ragged2e package documentation
Overleaf guides
- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Debugging Compilation timeout errors
- How-to guides
LaTeX Basics
- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Lists
- Errors
Mathematics
- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Fractions and Binomials
- Aligning Equations
- Operators
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts
Figures and tables
- Inserting Images
- Tables
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package
References and Citations
- Bibliography management in LaTeX
- Bibliography management with biblatex
- Biblatex bibliography styles
- Biblatex citation styles
- Bibliography management with natbib
- Natbib bibliography styles
- Natbib citation styles
- Bibliography management with bibtex
- Bibtex bibliography styles
Languages
- Multilingual typesetting on Overleaf using polyglossia and fontspec
- International language support
- Quotations and quotation marks
- Arabic
- Chinese
- French
- German
- Greek
- Italian
- Japanese
- Korean
- Portuguese
- Russian
- Spanish
Document structure
- Sections and chapters
- Table of contents
- Cross referencing sections and equations
- Indices
- Glossaries
- Nomenclatures
- Management in a large project
- Multi-file LaTeX projects
- Hyperlinks
Formatting
- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Counters
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Footnotes
- Margin notes
Fonts
Presentations
Commands
Field specific
- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typing exams in LaTeX
- Knitr
- Attribute Value Matrices
Class files
- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class
- Tips