Keywords: LaTeX | Equation Alignment | Left Alignment | fleqn | flalign Environment
Abstract: This paper comprehensively explores various technical solutions for achieving left-aligned equations in LaTeX. It begins by introducing the global left-alignment method using the fleqn document class option, suitable for scenarios requiring all equations in the document to be left-aligned. Subsequently, it analyzes the local left-alignment approach via the flalign environment, demonstrating through specific code examples how to achieve left-aligned arrangement for individual equation groups. The article also discusses techniques for controlling mathematical indentation, including adjustments to the mathindent parameter, enabling flexible control over the distance between equations and the left margin based on actual typesetting needs. Finally, through comparative analysis, it provides specific selection recommendations for different usage scenarios.
Introduction
In the typesetting process of academic papers and technical documents, the presentation of equations directly impacts the readability and aesthetics of the document. While LaTeX traditionally centers equations by default, left-aligned equation layouts can provide better visual effects in certain situations, particularly when equations are relatively short or need to align with left-side text. Based on practical usage requirements, this paper systematically introduces multiple technical solutions for achieving left-aligned equations in LaTeX.
Global Left Alignment: The fleqn Document Class Option
For scenarios requiring all equations throughout the document to adopt a left-aligned layout, the most direct and effective method is using the fleqn document class option. This approach achieves global alignment adjustment by adding option parameters to the document class declaration.
The specific implementation code is as follows:
\documentclass[fleqn]{article}
\usepackage{amsmath}
\begin{document}
\section{Mathematical Formula Examples}
The following equations will be automatically left-aligned:
\begin{align*}
|\vec a| &= \sqrt{3^{2}+1^{2}} = \sqrt{10} \\
|\vec b| &= \sqrt{1^{2}+23^{2}} = \sqrt{530} \\
\cos v &= \frac{26}{\sqrt{10} \cdot \sqrt{530}} \\
v &= \cos^{-1} \left(\frac{26}{\sqrt{10} \cdot \sqrt{530}}\right) \\
v &= \uuline{69.08...\degree}
\end{align*}
Single-line equations are also left-aligned:
\begin{align*}
f(x) = -1.25x^{2} + 1.5x
\end{align*}
\end{document}
The advantage of this method lies in its simplicity; only a one-time setup at the beginning of the document is required, and all subsequent mathematical environments (including equation, align, gather, etc.) will automatically adopt left alignment. However, this global setting also means that different alignment styles cannot be mixed within the document.
Local Left Alignment: The flalign Environment
When there is a need to mix different alignment styles within a document, the flalign environment provides a more flexible solution. This environment is specifically designed to achieve left alignment of equations while maintaining compatibility with other environments.
The basic usage format is as follows:
\begin{flalign*}
&|\vec a| = \sqrt{3^{2}+1^{2}} = \sqrt{10} & \\
&|\vec b| = \sqrt{1^{2}+23^{2}} = \sqrt{530} &\\
&\cos v = \frac{26}{\sqrt{10} \cdot \sqrt{530}} &\\
&v = \cos^{-1} \left(\frac{26}{\sqrt{10} \cdot \sqrt{530}}\right) &\\
\end{flalign*}
In the flalign environment, the & symbol is used to separate different alignment columns. Using & at the beginning of each line means the line starts with a blank column, thereby achieving left alignment for the entire equation group. The & at the end ensures the integrity of the alignment structure.
Mathematical Indentation Control
When using left-alignment schemes, the distance between the equation and the left margin is controlled by the \mathindent parameter. By default, LaTeX sets a certain indentation for left-aligned equations to maintain visual balance on the page.
If complete adherence to the left margin is needed, it can be adjusted with the following command:
\setlength{\mathindent}{0pt}
This command should be placed in the document preamble, after \usepackage{amsmath}. To restore the default indentation (usually 15pt), use:
\setlength{\mathindent}{15pt}
Practical Application Examples
To better understand the practical effects of different schemes, we demonstrate with a complete document example:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\section{Mixed Alignment Style Example}
Centered equation (default):
\begin{equation}
E = mc^2
\end{equation}
Left-aligned equation using flalign environment:
\begin{flalign}
&a_{ijk} = \frac {Pr(M_{I} =2 \& M_J=1 \& M_K =1 | I=i , J=j , K=k)}{Pr (M_I =1 \& M_J=1 \& M_K=1 | I=i , J=j)}&\\
&= \frac {\mu_{ijk211}}{\mu_{ijk111}}&
\end{flalign}
Single-line left-aligned equation:
\begin{flalign}
&f(x) = -1.25x^{2} + 1.5x&
\end{flalign}
\end{document}
Scheme Selection Recommendations
Based on practical application needs, we provide the following selection recommendations:
- Global Consistency Requirements: If the entire document requires a uniform left-aligned style, using the
fleqndocument class option is recommended, as it is simple to implement and easy to maintain. - Mixed Typesetting Requirements: When a document needs to include both centered and left-aligned equations, the
flalignenvironment should be used for local control. - Special Formatting Requirements: For scenarios requiring precise control over indentation, combining adjustments to the
\mathindentparameter allows for finer layout control.
Conclusion
LaTeX offers multiple flexible solutions for achieving left-aligned equation layouts. The global fleqn option is suitable for documents requiring uniform alignment styles, while the local flalign environment provides greater flexibility. By appropriately selecting and utilizing these tools, the typesetting quality and visual effectiveness of technical documents can be significantly enhanced. In practical applications, it is advisable to choose the most suitable scheme based on specific document requirements and typesetting specifications.