LaTeX give you the ability to align your paragraph(text). LaTeX contains an algorithm in the TeX program which by default renders paragraphs to be justified.
In other words, LaTeX stretches or shorten spaces between words to produce lines of text of equal lengths.
This article explains in detail how to change(modify) the alignments of portions of a text(paragraphs) or the entire body of text using LaTeX built-in commands and the ragged2e package.
Table of Contents
Writing can be single-column and also can be multi-column. Those columns can be aligned in different ways.
Such as left side, right side, along the middle and equally on both sides. The types are given below
Basic alignment: There Are two types of basic Alignment.
1. Single Column
2. Multi-Column
There is 4 type of each alignment basically exit.
1. Left
2. Right
3. Center
4. Fully Justified
Standard LATEX Environments and Commands
There are basically 3 environments that work by changing the declaration that control how TeX typesets your paragraphs.
These declarations are also available as LaTeX commands.
Environment | LaTeX command |
---|---|
center | \centering |
flushleft | \raggedleft |
flushright | \raggedright |
justify | \justifying |
The same environment and command for left, right, and center alignment is present in the ragged2e package.
However, there is no default command or environment for justify. In this case, you have to use this package.
Single Column Alignment
1. Left Align
If you want to single column left align text or figure or equation then you must have to use flushleft
environment. For left alignment text should be inserted into \begin{flushleft}
& \end{flushleft}
.
When you are going to write then you must have to follow the format order. Given below is the complete formula with an example.
\documentclass{article}
\usepackage[document]{ragged2e}
\begin{document}
\begin{flushleft}
\section{What is Lorem Ipsum?}
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
\subsection{Why do we use it?}
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution.
\end{flushleft}
\end{document}
Output :
2. Right Align
Same as the procedure you can align the right side for a single column. The difference between left and right just changes it flushleft
to the flashright
.
A complete format is given below for your proper instruction.
\documentclass{article}
\usepackage[document]{ragged2e}
\begin{document}
\begin{flushright}
\section{What is Lorem Ipsum?}
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
\subsection{Why do we use it?}
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution.
\end{flushright}
\end{document}
Output :
3. Center Align
If you want to align a paragraph to the center. Then you can also follow the usual rules of left alignment which are already discussed in the 1st rule.
Just change the center
instead of flushleft
. Already given the decorated format for example. Look at the below:
\documentclass{article}
\usepackage[document]{ragged2e}
\begin{document}
\begin{center}
\section{What is Lorem Ipsum?}
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
\subsection{Why do we use it?}
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution. Proin et massa et nisl porttitor tempor. Vestibulum volutpat enim nec orci egestas, sed iaculis lorem dignissim. Mauris nec lorem varius, malesuada nulla sit amet, posuere leo. Integer id risus et ligula tempus sagittis eu sit amet leo. Vestibulum maximus turpis aliquam neque ultrices imperdiet.
\end{center}
\end{document}
Output :
4. Justify Align
The ragged2e also provide us with the justified environment and command(\justifying
) which produces a justified text with a moderate amount of raggedness.
\documentclass{article}
\usepackage[document]{ragged2e}
\begin{document}
\begin{justify}
\section{What is Lorem Ipsum?}
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
\subsection{Why do we use it?}
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution. Proin et massa et nisl porttitor tempor. Vestibulum volutpat enim nec orci egestas, sed iaculis lorem dignissim. Mauris nec lorem varius, malesuada nulla sit amet, posuere leo. Integer id risus et ligula tempus sagittis eu sit amet leo. Vestibulum maximus turpis aliquam neque ultrices imperdiet.
\end{justify}
\end{document}
Output :
Multi-Column(two) Alignment
1. Left Align
As per our writing requirement, we can write text/equation/set image in double columns. If we want to write something in a double column then we need an extra packet of \usepackage{multicol}
than a single column.
In the wiring part, we have to set the paragraph between \begin{multicols}{2}
& \end{multicols}{2}
. Others part will as usual previous rules. For better understanding please look at the given format.
If you look at the code above, you will see that manual lorem text has been used. However, you can generate new ones instead of manually importing random text. There is a latex lipsum
package for this.
\documentclass{article}
\usepackage{multicol,lipsum}
\begin{document}
\begin{flushleft}
\begin{multicols}{2}
\section{What is Lorem Ipsum?}
\lipsum[1][1-7]
\subsection{Why do we use it?}
\lipsum[2][1-4]
\end{multicols}{2}
\end{flushleft}
\end{document}
Output :
2. Right Align
As like a single column, we can align a double-column right alignment. Just follow the left alignment rules which are already used in the double-column alignment but with major changes in the flushleft
to flushright
.
Already shown below furnished structure and example, please look at this for your practice.
\documentclass{article}
\usepackage{multicol,lipsum}
\begin{document}
\begin{flushright}
\begin{multicols}{2}
\section{What is Lorem Ipsum?}
\lipsum[1][1-7]
\subsection{Why do we use it?}
\lipsum[2][1-4]
\end{multicols}{2}
\end{flushright}
\end{document}
Output :
3. Center Align
Maximum times this structure is used for images or equation align.
In the double-column center alignment used package is \usepackage{multicol}
and variation from others alignment is \begin{center}
& \end{center}
instant of \begin{flushright}
& \end{flushright}
.
Proper format and example already discussed below
\documentclass{article}
\usepackage{multicol,lipsum}
\begin{document}
\begin{center}
\begin{multicols}{2}
\section{What is Lorem Ipsum?}
\lipsum[1][1-7]
\subsection{Why do we use it?}
\lipsum[2][1-4]
\end{multicols}{2}
\end{center}
\end{document}
Output :
4. Fully justified Align
Single column fully justified alignment & double column fully justified alignment same procedure just added an extra package \usepackage{multicol}
and used \begin{multicols}{2}
& \end{multicols}{2}
Front and back in the text.
Please follow the format and example which will give you clear understanding of it.
\documentclass{article}
\usepackage[document]{ragged2e}
\usepackage{multicol,lipsum}
\begin{document}
\begin{justify}
\begin{multicols}{2}
\section{What is Lorem Ipsum?}
\lipsum[1][1-7]
\subsection{Why do we use it?}
\lipsum[2][1-4]
\end{multicols}{2}
\end{justify}
\end{document}
Output :
Use commands instead of environment
Environment has been used in the above case. You can do the same thing by putting commands before paragraphs instead of environment. But, you need a ragged2e package to justify it.
\documentclass{article}
\usepackage[document]{ragged2e}
\usepaxkage{xcolor}
\begin{document}
\RaggedRight {\color{red} \verb|\RaggedRight| }\\ It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages.\\
\Centering {\color{red}\verb|\Centering| }\\ Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.\\
\RaggedLeft {\color{red}\verb|\RaggedLeft|} \\It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages.\\
\justifying {\color{red}\verb|\justifying| }\\ Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
}
\end{document}
Output :