Aller au contenu

Introduction

This article introduces basic LaTeX paragraph formatting, including how to change text alignment. More detailed information, and further examples, can be found in the articles Text alignment and Paragraph formatting.

A first example

Let's start with an example which typesets two centred paragraphs by writing them inside a center environment. Note how a new paragraph is started by inserting a blank line between them—although that's a commonly-used method, it's not the only way to start a new paragraph.

\begin{center}
Example 1: The following paragraph (given in quotes) is an 
example of centred alignment using the center environment. 

``La\TeX{} is a document preparation system and document markup 
language. \LaTeX{} uses the \TeX{} typesetting program for formatting 
its output, and is itself written in the \TeX{} macro language. 
\LaTeX{} is not the name of a particular (executable) typesetting program, but 
refers to the suite of commands (\TeX{} macros) which form the markup 
conventions used to typeset \LaTeX{} documents."
\end{center}

 Open this example in Overleaf

This example produces the following output:

LaTeX centred paragraph example

Starting a new paragraph

As noted above, one way to start a new paragraph is by inserting a blank line but the following code snippet shows an alternative solution which uses the \par command:

This is text contained in the first paragraph. 
This is text contained in the first paragraph. 
This is text contained in the first paragraph.\par
This is text contained in the second paragraph. 
This is text contained in the second paragraph.
This is text contained in the second paragraph.

 Open this example in Overleaf

This example produces the following output:

Using the \par command to create a paragraph

Paragraph alignment

By default paragraphs in LaTeX are fully justified, i.e. flush with both the left and right margins. If you would like to typeset an unjustified paragraph you can use the flushleft or flushright environments.

flushleft and flushright environments

The next example demonstrates typesetting a paragraph within the flushleft and flushright environments—for an example of the center environment see the section A first example.

\section*{A paragraph typeset flush left}

\begin{flushleft}
La\TeX{} is a document preparation system and document markup 
language. \LaTeX{} uses the \TeX{} typesetting program for formatting 
its output, and is itself written in the \TeX{} macro language. 
\LaTeX{} is not the name of a particular (executable) typesetting program, but 
refers to the suite of commands (\TeX{} macros) which form the markup 
conventions used to typeset \LaTeX{} documents.
\end{flushleft}

\section*{A paragraph typeset flush right}

\begin{flushright}
La\TeX{} is a document preparation system and document markup 
language. \LaTeX{} uses the \TeX{} typesetting program for formatting 
its output, and is itself written in the \TeX{} macro language. 
\LaTeX{} is not the name of a particular (executable) typesetting program, but 
refers to the suite of commands (\TeX{} macros) which form the markup 
conventions used to typeset \LaTeX{} documents.
\end{flushright}

 Open this example in Overleaf

This example produces the following output:

LaTeX flushleft anf flushright environments

\raggedright and \raggedleft

An alternative to using environments such as flushleft, flushright or center are the so-called "switch" commands:

  • \raggedright, an alternative to using the flushleft environment
  • \raggedleft, an alternative to using the flushright environment
  • \centering, an alternative to using the center environment

These switch commands change text alignment from the point they are inserted down to the end of the document—unless their effect(s) are restricted to a group or changed by another switch command.

In the following example, the effects of \raggedright, \raggedleft and \centering are localized because they are used within the group created by \begingroup ... \endgroup. In addition, note that in each case the paragraph text is followed by a blank line, before the \endgroup command, which triggers LaTeX to typeset the paragraph whilst the settings applied by \raggedright, \raggedleft and \centering are still active.

\section*{A fully justified  typeset paragraph} 
\LaTeX{} is not the name of a particular (executable) typesetting program, but refers to the suite of commands (\TeX{} macros) which form the markup 
conventions used to typeset \LaTeX{} documents.

\section*{A paragraph typeset using \texttt{\string\raggedright}}

\begingroup
\raggedright 
\LaTeX{} is not the name of a particular (executable) typesetting program, but refers to the suite of commands (\TeX{} macros) which form the markup 
conventions used to typeset \LaTeX{} documents.

\endgroup

\section*{A paragraph typeset using \texttt{\string\raggedleft}}

\begingroup
\raggedleft 
\LaTeX{} is not the name of a particular (executable) typesetting program, but refers to the suite of commands (\TeX{} macros) which form the markup 
conventions used to typeset \LaTeX{} documents.

\endgroup

\section*{A paragraph typeset using \texttt{\string\centering}}

\begingroup
\centering 
\LaTeX{} is not the name of a particular (executable) typesetting program, but refers to the suite of commands (\TeX{} macros) which form the markup 
conventions used to typeset \LaTeX{} documents.

\endgroup

 Open this example in Overleaf

This example produces the following output:

Various alignment options for typesetting a LaTeX paragraph

For more detailed information and examples of text alignment see the Overleaf article on text alignment which also discusses using the ragged2e LaTeX package to typeset ragged text and configure hyphenation.

Paragraph indentation

By default new paragraphs are usually indented by an amount controlled by a parameter called \parindent whose value can be set using the command \setlength; for example:

\setlength{\parindent}{20pt}

sets \parindent to 20pt. You can avoid indentation by setting \parindent to 0pt (or 0mm, 0cm etc) or using the command \noindent at the beginning of the paragraph. By default LaTeX does not indent the first paragraph contained in a document section as demonstrated in the following example:

\setlength{\parindent}{20pt}

\section*{This is a section}
\textbf{First paragraph} of a section which, as you can see, is not indented. This is more text in the paragraph. This is more text in the paragraph.

\textbf{Second paragraph}. As you can see it is indented. This is more text in the paragraph. This is more text in the paragraph. 

\noindent\textbf{Third paragraph}. This too is not indented due to use of \texttt{\string\noindent}. This is more text in the paragraph. This is more text in the paragraph.  The current value of \verb|\parindent| is \the\parindent. This is more text in the paragraph.

 Open this example in Overleaf

This example produces the following output:

Demonstrating LaTeX paragraph indentation

Notes on indentation-related commands

Paragraph indentation is controlled or influenced by three commands:

  • \parindent: a parameter which stores the current size of the paragraph indent
  • \indent: the effect of this command depends where it is used:
    • in a horizontal mode (inside a paragraph or an \hbox) or math mode it inserts a space (an empty box) of width \parindent
    • in a vertical mode (between paragraphs or in a \vbox) it triggers the start a new indented paragraph
  • \noindent: the effect of this command also depends where it is used:
    • in a vertical mode (between paragraphs or in a \vbox) it also triggers a new non-indented paragraph
    • in a horizontal mode (inside a paragraph or an \hbox) or math mode it has no effect: it is ignored

The following example demonstrates \indent:

\documentclass{article}
% Using the geometry package with a small
% page size to create the article graphic
\usepackage[paperheight=6in,
   paperwidth=5in,
   top=10mm,
   bottom=20mm,
   left=10mm,
   right=10mm]{geometry}
\begin{document}
\noindent A new paragraph with some text, then an \verb|\indent|\indent command. Next, some inline math which also has an indent $y\indent x$. \verb|\indent| also works when used in an \verb|\hbox| such as \verb|\hbox{A\indent B}| which produces \hbox{A\indent B}.
\end{document}

 Open this example in Overleaf

This example produces the following output:

Demonstrating the \indent command

Further Reading

For more information check

Overleaf guides

LaTeX Basics

Mathematics

Figures and tables

References and Citations

Languages

Document structure

Formatting

Fonts

Presentations

Commands

Field specific

Class files

Advanced TeX/LaTeX