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.

AlignmentDefault commandDefault environmentragged2e commandragged2e environment
Left\raggedrightflushleft\RaggedRightFlushLeft
Right\raggedleftflushright\RaggedLeftFlushRight
Center\centeringcenter\CenteringCenter
JustifyN/AN/A\justifyingjustify

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 commands.

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 default environment.

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 commands.

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:

Text alignment with ragged2e package environment.

Leave a Reply

Your email address will not be published. Required fields are marked *