×
Klik hier om ShareLaTeX te gebruiken in het Engels

[edit] ShareLaTeX guides

[edit] LaTeX Basics

[edit] Mathematics

[edit] Figures and tables

[edit] References and Citations

[edit] Languages

[edit] Document structure

[edit] Formatting

[edit] Fonts

[edit] Presentations

[edit] Commands

[edit] Field specific

[edit] Class files

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.

Contents

[edit] 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 show 
what aprinted text will look like at this place.  If you read this 
text, you will get noinformation...
 
\end{document}

TextAlignementEx1.png

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.

  Open an example in ShareLaTeX

[edit] Using the package ragged2e

There are several standard LaTeX commands to change the text alignment. Alternativaly 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.

TextAlignementEx2.png

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 ShareLaTeX

[edit] 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.

TextAlignmentEx3.png

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.

  Open an example in ShareLaTeX

[edit] 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.

TextAlignmentEx4.png

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.

  Open an example in ShareLaTeX

[edit] 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.

TextAlignmentEx5.png

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.

  Open an example in ShareLaTeX

[edit] 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 raged2e. 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.

TextAlignmentEx6.png

The first paragraph in the previous example is centred by \centering and then the alignment is switched back to fully-justified text with \justify.

raged2e 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 ShareLaTeX

[edit] 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 ShareLaTeX

[edit] Further reading

For more information see :