HowTo Frame Two Align* Environments Side-by-side
Introduction
When working with mathematical equations, it's often necessary to display multiple equations side-by-side for comparison or to illustrate a relationship between them. In LaTeX, the align*
environment is commonly used to typeset equations, but by default, it will not allow you to place two align*
environments side-by-side. In this article, we will explore how to frame two align*
environments side-by-side using various techniques.
The Problem
Let's start with the basic setup. We have a LaTeX document with the following code:
\documentclass[a4paper,10pt]{article}
\usepackage{amsmath}
\usepackage{stix2}% must follow amsmath or arrows get flinky.
\usepackage[g]{esvect}
\begin{document}
\begin{align*}
\text{Equation 1} &= \text{expression 1} \
\text{Equation 2} &= \text{expression 2}
\end{align*}
\end{document}
This will produce two equations, one below the other. However, if we want to place two align*
environments side-by-side, we will encounter an error.
Method 1: Using the minipage
Environment
One way to frame two align*
environments side-by-side is to use the minipage
environment. The minipage
environment allows you to create a box of a specified width, which can then be used to typeset the equations.
\documentclass[a4paper,10pt]{article}
\usepackage{amsmath}
\usepackage{stix2}% must follow amsmath or arrows get flinky.
\usepackage[g]{esvect}
\begin{document}
\begin{minipage}[b]{0.45\textwidth}
\begin{align*}
\text{Equation 1} &= \text{expression 1} \
\text{Equation 2} &= \text{expression 2}
\end{align*}
\end{minipage}\hfill
\begin{minipage}[b]{0.45\textwidth}
\begin{align*}
\text{Equation 3} &= \text{expression 3} \
\text{Equation 4} &= \text{expression 4}
\end{align*}
\end{minipage}
\end{document}
In this example, we use the minipage
environment to create two boxes, each with a width of 45% of the text width. We then use the \hfill
command to create a horizontal fill between the two boxes.
Method 2: Using the subfigure
Package
Another way to frame two align*
environments side-by-side is to use the subfigure
package. This package allows you to create subfigures, which can be used to typeset the equations.
\documentclass[a4paper,10pt]{article}
\usepackage{amsmath}
\usepackage{stix2}% must follow amsmath or arrows get flinky.
\usepackage[g]{esvect}
\usepackage{subfigure}
\begin{document}
\begin{figure}[h]
\centering
\subfigure[Equation 1]{
\begin{minipage}[b]{0.45\textwidth}
\begin{align*}
\text{Equation 1} &= \text{expression 1} \
\text{Equation 2} &= \text{expression 2}
\end{align*}
\end{minipage}
}
\subfigure[Equation 2]{
\begin{minipage}[b]{0.45\textwidth}
\begin{align*}
\text{Equation 3} &= \text{expression 3} \
\text{Equation 4} &= \text{expression 4}
\end{align*}
\end{minipage}
}
\end{figure}
\end{document}
In this example, we use the subfigure
package to create two subfigures, each with a width of 45% of the text width. We then use the \centering
command to center the subfigures.
Method 3: Using the alignat
Environment
A third way to frame two align*
environments side-by-side is to use the alignat
environment. This environment allows you to typeset multiple equations with a specified alignment.
\documentclass[a4paper,10pt]{article}
\usepackage{amsmath}
\usepackage{stix2}% must follow amsmath or arrows get flinky.
\usepackage[g]{esvect}
\begin{document}
\begin{alignat*}{2}
\text{Equation 1} &= \text{expression 1} & \text{Equation 3} &= \text{expression 3} \
\text{Equation 2} &= \text{expression 2} & \text{Equation 4} &= \text{expression 4}
\end{alignat*}
\end{document}
In this example, we use the alignat
environment to typeset two equations with a specified alignment.
Conclusion
Q: What is the purpose of framing two align environments side-by-side?*
A: Framing two align*
environments side-by-side is useful when you want to display multiple equations for comparison or to illustrate a relationship between them.
Q: Why can't I simply use two align environments side-by-side?*
A: The align*
environment is designed to typeset a single equation, and it will not allow you to place two align*
environments side-by-side. You need to use a different approach, such as the minipage
environment, the subfigure
package, or the alignat
environment.
Q: How do I use the minipage environment to frame two align environments side-by-side?*
A: To use the minipage
environment, you need to create two boxes, each with a width of 45% of the text width. You can then use the \hfill
command to create a horizontal fill between the two boxes.
\documentclass[a4paper,10pt]{article}
\usepackage{amsmath}
\usepackage{stix2}% must follow amsmath or arrows get flinky.
\usepackage[g]{esvect}
\begin{document}
\begin{minipage}[b]{0.45\textwidth}
\begin{align*}
\text{Equation 1} &= \text{expression 1} \
\text{Equation 2} &= \text{expression 2}
\end{align*}
\end{minipage}\hfill
\begin{minipage}[b]{0.45\textwidth}
\begin{align*}
\text{Equation 3} &= \text{expression 3} \
\text{Equation 4} &= \text{expression 4}
\end{align*}
\end{minipage}
\end{document}
Q: How do I use the subfigure package to frame two align environments side-by-side?*
A: To use the subfigure
package, you need to create two subfigures, each with a width of 45% of the text width. You can then use the \centering
command to center the subfigures.
\documentclass[a4paper,10pt]{article}
\usepackage{amsmath}
\usepackage{stix2}% must follow amsmath or arrows get flinky.
\usepackage[g]{esvect}
\usepackage{subfigure}
\begin{document}
\begin{figure}[h]
\centering
\subfigure[Equation 1]{
\begin{minipage}[b]{0.45\textwidth}
\begin{align*}
\text{Equation 1} &= \text{expression 1} \
\text{Equation 2} &= \text{expression 2}
\end{align*}
\end{minipage}
}
\subfigure[Equation 2]{
\begin{minipage}[b]{0.45\textwidth}
\begin{align}
\text{Equation 3} &= \text{expression 3} \
\text{Equation 4} &= \text{expression 4}
\end{align*}
\end{minipage}
}
\end{figure}
\end{document}
Q: How do I use the alignat environment to frame two align environments side-by-side?*
A: To use the alignat
environment, you need to specify the number of columns and the alignment of the equations.
\documentclass[a4paper,10pt]{article}
\usepackage{amsmath}
\usepackage{stix2}% must follow amsmath or arrows get flinky.
\usepackage[g]{esvect}
\begin{document}
\begin{alignat*}{2}
\text{Equation 1} &= \text{expression 1} & \text{Equation 3} &= \text{expression 3} \
\text{Equation 2} &= \text{expression 2} & \text{Equation 4} &= \text{expression 4}
\end{alignat*}
\end{document}
Q: What are the advantages and disadvantages of each method?
A: The minipage
environment is a simple and straightforward method, but it can be cumbersome to use if you have many equations. The subfigure
package is more flexible and allows you to create subfigures with different widths and heights. The alignat
environment is the most flexible method, but it can be difficult to use if you have many equations.
Q: Can I use other environments to frame two align environments side-by-side?*
A: Yes, you can use other environments, such as the tabular
environment or the array
environment, to frame two align*
environments side-by-side. However, these environments may require more complex code and may not be as flexible as the minipage
environment, the subfigure
package, or the alignat
environment.