How to Align Text In LaTeX
By default, LaTeX aligns text using a fully justified method. In most cases, this method works great, especially when working with Mathematical formulas or chemical equations.
However, to use a custom alignment method, we need to import the ragged2e package. You can do this by setting the entry below in your document preamble.
The example code below shows how to use the ragged2e package. As mentioned, the text is aligned to the left unless explicitly specified.
\usepackage[utf8]{inputenc}
\usepackage[document]{ragged2e}
\begin{document}
\title{Text Alignment}
\author{Linuxhint}
\maketitle
\section{Using Ragged2e Package}
----------------------TEXT BLOCKS----------------------
--------------------------------------------------------------
\end{document}
The above code should give a sample document similar to the one shown below:
Left Justify Text
To use left-alignment on a document, use the FlushLeft command. The general syntax for left-align text is:
\end{FlushLeft}
The following sample code illustrates how to use the flush left command.
\usepackage[utf8]{inputenc}
\usepackage[document]{ragged2e}
\begin{document}
\title{Text Alignment}
\author{Linuxhint}
\maketitle
\section{Using Ragged2e Package}
\begin{FlushLeft}
-------------- Document content here---------------------
---------------------------------------------------------------
\end{FlushLeft}
\end{document}
This will align the text to the left; here is an example output:
Right Align Text
To align text to the right, use the RightAlign command. The syntax for that is:
\end{FlushRight}
The following example illustrates how the command works.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[document]{ragged2e}
\begin{document}
\title{Text Alignment}
\author{Linuxhint}
\maketitle
\section{Using Ragged2e Package}
\begin{FlushRight}
---------------------Document content here----------------
----------------------------------------------------------------
\end{FlushRight}
\end{document}
The output result for this command are:
NOTE: LaTeX also supports the RaggedLeft command to align text to the right. The syntax for that is:
Center Align Text
To align text to the center using the ragged2e package, use the Center command as:
\end{center}
The resulting alignment for this is:
Full Justify Text
By default, LaTeX fully justifies text in LaTeX documents. However, you can explicitly specify this if you are using a different alignment method.
To do this, use the \justify command.
LaTeX aligns the resulting content as shown below:
How to Align Equations In LaTeX
The amsmath package determines equations and formula alignment in LaTeX documents. Import the package by adding the entry below in the document preamble.
For Simple Equations:
To write a simple equation, use the equation environment as:
TERMS
\end{equation}
The following example code shows how to add an equation to a document.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\begin{document}
\title{Aligning Formulas}
\author{Linuxhint}
\maketitle
\section{Writing a simple equation}
\begin{equation*}
E = mc^2
\end{equation*}
The output for this is:
NOTE: If you want the equation numbered, use the equation environment (without an asterisk) as shown below:
E = mc^2
\end{equation}
For Long Equations
To display equations that span more than a single line, use the {multiline*} environment. As:
\end{multiline*}
An example for that is:
\begin{multline*}
a(b) = c^c + d_{c} \\
- e(a) - f^g
\end{multline*}
The output for this is:
How to Align an Equation
You can align an equation by using {align*} environment. The general syntax is:
\end{align*}
For example, the example below aligns the equations vertically.
\begin{align*}
y-9 = 25 \\
x + 15 = 6 \\
3x = 9 \\
\end{align*}
You can also align the by columns, as shown by the code below:
x&=y & a&=b \\
a^2 + b2 = c^2 & & ab=\sqrt{23}
\end{align*}
The example above aligns the equations in two columns. Here is a sample output:
Conclusion
This tutorial has shown you how to use LaTeX alignment features and packages to align text and formulates.
from Linux Hint https://ift.tt/3zdHDwt
0 Comments