Text alignment (left, right, center, and justify) in LaTeX
LaTeX provides you with some default commands for text alignment in LaTeX documents. which you can use to align text left, right, or center. But to use text-justify features you need to use the ragged2e
package.
However, this package also provides some commands to left, right, and center text, whose output is slightly better than the default.
In this tutorial, I’ll show you how you can align text using the default command and the ragged2e
package.
Alignment | Default command | Default environment | ragged2e command | ragged2e environment |
---|---|---|---|---|
Left | \raggedright | flushleft | \RaggedRight | FlushLeft |
Right | \raggedleft | flushright | \RaggedLeft | FlushRight |
Center | \centering | center | \Centering | Center |
Justify | N/A | N/A | \justifying | justify |
Text alignment with default commands
In the table above you can see all the commands required for alignment. Use the command you need before any sentence and use the \par
command at the end of the sentence (or paragraph).
\documentclass{article} \usepackage{lipsum} \begin{document} \section{Without any alignment} \lipsum[1][1-9]\par \section{Text align left using \texttt{\string\raggedright}} \raggedright\lipsum[1][1-9]\par \section{Text align right using \texttt{\string\raggedleft}} \raggedleft\lipsum[1][1-9]\par \raggedright\section{Text align center using \texttt{\string\centering}} \centering\lipsum[1][1-9]\par \end{document}
Output:
Text alignment with default environments
In this case, you just need to write the sentence or paragraph inside the environment you need. Take a look.
\documentclass{article} \usepackage{lipsum} \begin{document} \section{Without any alignment} \lipsum[1][1-9]\par \section{Text align left using \texttt{flushleft}} \begin{flushleft} \lipsum[1][1-9] \end{flushleft} \section{Text align right using \texttt{flushright}} \begin{flushright} \lipsum[1][1-9] \end{flushright} \section{Text align center using \texttt{center}} \begin{center} \lipsum[1][1-9] \end{center} \end{document}
Output:
Text alignment with ragged2e package commands
The ragged2e
provides you with some commands similar to the default commands for text alignment, which you can see in the table above. And these commands have to be used in a similar way to before.
\documentclass{article} \usepackage{lipsum} \usepackage{ragged2e} \begin{document} \section{Text alignment with default \texttt{\string\raggedright}} \raggedright\lipsum[1][1-9]\par \section{Text align left using \texttt{\string\RaggedRight}} \RaggedRight\lipsum[1][1-9]\par \raggedright\section{Text align right using \texttt{\string\RaggedLeft}} \RaggedLeft\lipsum[1][1-9]\par \raggedright\section{Text align center using \texttt{\string\Centering}} \Centering\lipsum[1][1-9]\par \raggedright\section{Text align justify using \texttt{\string\justifying}} \justifying\lipsum[1][1-9]\par \end{document}
Output:
Text alignment with ragged2e package environments
Enter the text or paragraph inside the environment you need. Check out some examples.
\documentclass{article} \usepackage{lipsum} \usepackage{ragged2e} \begin{document} \section{Text alignment with default \texttt{\string\raggedright}} \raggedright\lipsum[1][1-9]\par \section{Text align left using \texttt{FlushLeft}} \begin{FlushLeft} \lipsum[1][1-9] \end{FlushLeft} \section{Text align right using \texttt{FlushRight}} \begin{FlushRight} \lipsum[1][1-9] \end{FlushRight} \section{Text align center using \texttt{Center}} \begin{Center} \lipsum[1][1-9] \end{Center} \section{Text align justify using \texttt{justify}} \begin{justify} \lipsum[1][1-9] \end{justify} \end{document}
Output:
Leave a Reply