# How to align text in multiple separate align environments [duplicate]

EDIT: I disagree about the duplicity of my question. My question is slightly different and the solution given by Bernard is much better than solutions given to Align multiple numbered aligned blocks.

I want the conditions of each equations to be aligned like so

but my code

\documentclass[a4paper,11pt,oneside]{paper}

\usepackage[fleqn]{amsmath} % Matematika
\usepackage{fontenc}
\usepackage{polyglossia}
\setdefaultlanguage{czech}

\begin{document}

\textbf{Something A}
\begin{subequations}
\begin{alignat}{2}
&\beta_{a} = 2,00           && \qquad \text{for } f < 50\\
&\beta_{a} = 2,00 + 1 + 2   && \qquad \text{for } f > 50
\end{alignat}
\end{subequations}

\textbf{Something B}
\begin{subequations}
\begin{alignat}{2}
&\beta_{b} = 2,00                   && \qquad \text{for } f < 50\\
&\beta_{b} = 2,00 + 1 + 2 + 3 + 4   && \qquad \text{for } f > 50
\end{alignat}
\end{subequations}

\textbf{Something C}
\begin{subequations}
\begin{alignat}{2}
&\beta_{c} = 2,00                           && \qquad \text{for } f < 50\\
&\beta_{c} = 2,00 + 1 + 2 + 3 + 4 + 5 + 6   && \qquad \text{for } f > 50
\end{alignat}
\end{subequations}

\end{document}


currently produces this

How could I change the code to get the desired output?

I tried to put \hfill before the \text{for } f < 50 and \qquad after that but apparently \hfill doesn't work in align environment.

## marked as duplicate by JPi, Stefan Pinnow, user36296, Mensch, CarLaTeXJul 20 '17 at 15:40

An automated alignment with eqparbox. I took the liberty to align equations an the = sign rather than on their l.h.s. Also, I think \qquad should be placed between the two columns, not at the beginning of the second column. It does not make much change in the case at hand, but it's more satisfactory from a semantic point of view.

\documentclass[a4paper,11pt,oneside]{paper}

\usepackage[fleqn]{mathtools} % Matematika
\usepackage{polyglossia}
\setdefaultlanguage{czech}
\usepackage{eqparbox}
\newcommand{\eqmathbox}[2][M]{\eqmakebox[#1][l]{$\displaystyle#2$}}

\begin{document}

\textbf{Something A}
\begin{subequations}
\begin{alignat}{2}
\beta_{a} & = 2,00 & \qquad & \text{for } f < 50 \\
\beta_{a} & = \eqmathbox{2,00 + 1 + 2 } & \qquad & \text{for } f > 50
\end{alignat}
\end{subequations}

\textbf{Something B}
\begin{subequations}
\begin{alignat}{2}
\beta_{b} & = 2,00 & \qquad & \text{for } f < 50 \\
\beta_{b} & =\eqmathbox{2,00 + 1 + 2 + 3 + 4} & \qquad & \text{for } f > 50
\end{alignat}
\end{subequations}

\textbf{Something C}
\begin{subequations}
\begin{alignat}{2}
\beta_{c} & = 2,00 & \qquad & \text{for } f < 50 \\
\beta_{c} & =\eqmathbox{2,00 + 1 + 2 + 3 + 4 + 5 + 6} & \qquad & \text{for } f > 50
\end{alignat}
\end{subequations}

\end{document}


• I am fairly new to Latex, could you please explain the syntax of: \newcommand{\eqmathbox}[2][M]{\eqmakebox[#1][l]{$\displaystyle#2$}}? I am mainly confused about the [M] part and the fact that there are 2 parameters but then in code I input only 1 parameter. – Jakub Holan Jul 20 '17 at 13:53
• Oh! yes. The eqparbox package defines versions of \makebox, \parbox, &c., where the length argument is replace with a tag. All boxes sharing the same tag have for length the natural length of the widest argument of all boxes. Here, I turn this tag into an optional argument by defining a default value (M for math), but of course, if you have several series of equations, you'll have to use other tags, say \eqmathbox[M1]{some equation}, ar any tag you please. I hope I'm clear, but anyway, you should definitely take a look at the (short) documentation of eqparbox. – Bernard Jul 20 '17 at 14:02
• Thanks! I did take look at the documentation as well as the explanations of \makebox and \newcommand here but I was still confused about the "making tag an optional argument by defining the default value". Now I get it :) – Jakub Holan Jul 20 '17 at 14:46

Simply make all three subequations have equal widths by replacing each first subequation by, for example, \makebox[15em][l]{$<first subequation>$}.

Edit:

It is possible to choose the longest of the subequations in advance to set the width of all remaining subequations as it. For example:

\newlength\eqlength
\settowidth\eqlength{$\beta_{c} = 2,00 + 1 + 2 + 3 + 4 + 5 + 6$}


stores the width of the longest subequation to a register \eqlength. Then, this register can be used in \makebox[\eqlength][l]{$...$}.

\documentclass[a4paper,11pt,oneside]{paper}

\usepackage[fleqn]{amsmath} % Matematika
\usepackage{fontenc}
\usepackage{polyglossia}
\setdefaultlanguage{czech}

\begin{document}

\textbf{Something A}
\begin{subequations}
\begin{alignat}{2}
&\makebox[15em][l]{$\beta_{a} = 2,00$}      && \qquad \text{for } f < 50\\
&\beta_{a} = 2,00 + 1 + 2                   && \qquad \text{for } f > 50
\end{alignat}
\end{subequations}

\textbf{Something B}
\begin{subequations}
\begin{alignat}{2}
&\makebox[15em][l]{$\beta_{a} = 2,00$}      && \qquad \text{for } f < 50\\
&\beta_{b} = 2,00 + 1 + 2 + 3 + 4           && \qquad \text{for } f > 50
\end{alignat}
\end{subequations}

\textbf{Something C}
\begin{subequations}
\begin{alignat}{2}
&\makebox[15em][l]{$\beta_{a} = 2,00$}      && \qquad \text{for } f < 50\\
&\beta_{c} = 2,00 + 1 + 2 + 3 + 4 + 5 + 6   && \qquad \text{for } f > 50
\end{alignat}
\end{subequations}

\end{document}


• Nice and simple solution but I do need to know the length of the longest right equation in advance and I do have to check if the "for f < 50" isn't too far right (in collision with numbering). Is there a way to tell Latex to align the left side on the first letter "p" and position in so that the last letter "a" is x length from the end of line? – Jakub Holan Jul 20 '17 at 13:54
• @JakubHolan -- I added and edit to demonstrate how to set the width as the longest subequation in advance. – AboAmmar Jul 20 '17 at 14:14