0

As the title already indicates I have an equation which contains multiple cells and I want the content of each cell to be left aligned. Following this answer I tried used flalign however this seems to just left-align the overall equation. The following is a small example:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{flalign*}
  \textrm{Some stuff about } \rho & & \\
  \qquad \textrm{This is a really long equation and the following} \qquad & \textrm{should be left aligned} & \\
  \qquad \textrm{Short equation (should be left too)}              \qquad & \textrm{but quite a long one on the right though} &
\end{flalign*}

\end{document}

This example produces the following output (I put some remarks to indicate what I would like to achieve):

output

After doing some research I got the feeling that either of these two approaches should do but I can't get it working.

Following the first approach I tried:

\documentclass{article}
\usepackage{amsmath}
\usepackage{calc}

\newcommand*{\mbc}[2]{\makebox[\widthof{$F(\alpha)$}][#1]{$#2$}}

\begin{document}

\begin{flalign*}
  \mbc{l}{\textrm{Some stuff about } \rho} & & \\
  \qquad \textrm{This is a really long equation and the following} \qquad & \textrm{should be left aligned} & \\
  \qquad \textrm{Short equation (should be left too)}              \qquad & \textrm{but quite a long one on the right though} &
\end{flalign*}

\end{document}

Surprisingly the first line now seems to end up in the second cell (instead of being left aligned in the first cell):

output with \mbc

The second approach doesn't seem to work with math symbols:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\pushleft}[1]{\ifmeasuring@#1\else\omit$\displaystyle#1$\hfill\fi\ignorespaces}

\begin{document}

\begin{flalign*}
  \pushleft{\textrm{Some stuff about } \rho} & & \\
  \qquad \textrm{This is a really long equation and the following} \qquad & \textrm{should be left aligned} & \\
  \qquad \textrm{Short equation (should be left too)}              \qquad & \textrm{but quite a long one on the right though} &
\end{flalign*}

\end{document}

Gives the output:

$ pdflatex test.tex
[...]
! Undefined control sequence.
\pushleft #1->\ifmeasuring 
                           @#1\else \omit $\displaystyle #1$\hfill \fi \igno...
l.20 \end{flalign*}

Inserting additional $$ doesn't help either. The closest I could get was by using \omit and \hfill however \omit seems to opt out of math mode so I need to insert additional $$:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{flalign*}
  \omit $\textrm{Some stuff about } \rho$ \hfill & & \\
  \omit $\qquad \textrm{This is a really long equation and the following} \qquad$ \hfill & \textrm{should be left aligned} & \\
  \omit $\qquad \textrm{Short equation (should be left too)}              \qquad$ \hfill & \textrm{but quite a long one on the right though} &
\end{flalign*}

\end{document}

output with \omit and \hfill

It works however my IDE is marking the extra $$ as errors all over the place which is definitely not pleasant. Also I'm not sure if this is a clean solution that will always work as expected.

Does anybody have an idea how to achieve cell-wise left-alignment in an equation containing math symbols? Or any comments on the latter \omit-\hfill-$$-approach?

2

Like this?

\documentclass{article}
\usepackage{mathtools}
\usepackage[showframe]{geometry}

\begin{document}

\begin{flalign*}
 & \textrm{Some stuff about } \rho & & \\
  & \qquad \textrm{This is a really long equation and the following} && \textrm{should be left aligned} \\
  & \qquad \textrm{Short equation (should be left too)} & & \textrm{but quite a long one on the right though}
\end{flalign*}

\end{document} 

enter image description here

Example code for other alignments:

\documentclass{article}
\usepackage{mathtools}
\usepackage[showframe]{geometry}

\begin{document}

\begin{flalign*}
  \shortintertext{\texttt{Columns left-aligned:} } 
  & \textrm{Some stuff about } \rho  \\
  & \qquad \textrm{This is a really long equation and the following} && \textrm{should be left aligned} \\
  & \qquad \textrm{Short equation (should be left too)} & & \textrm{but quite a long one on the right though}
\end{flalign*}

\begin{flalign*}
  \shortintertext{\texttt{Columns right-aligned:} } 
  & \rlap{Some stuff about $\rho $} \\
  & & \textrm{This is a really long equation and the following}& & \textrm{should be right aligned}& \\
  & &\textrm{Short equation (should be rightt too)} && \textrm{but quite a long one on the right though}&
\end{flalign*}

\begin{flalign*}
  \shortintertext{\texttt{Left column centred, right column left-aligned: }}
  & \textrm{Some stuff about } \rho  \\
  & \begin{gathered} \textrm{This is a really long equation and the following}\\\textrm{Short equation (should be centred)}\end{gathered}
  & \begin{aligned} & \textrm{should be left aligned} \\
  & \textrm{but quite a long one on the right though}\end{aligned}&
\end{flalign*}

\end{document} 

enter image description here

  • Yes, decent solution! Do you mind explaining why this works? Is it that - within align - even columns are right-aligned and odd columns are left-aligned and so we just omit the even ones? – a_guest Jul 6 '17 at 15:24
  • No. People often misunderstand the syntax with &: actually k alignment points require 2k – 1 &: From the second column of alignment, a first & points out the beginning of a new column, and the second & points the exact alignment in that column. For the first column, it is not necessary to point out its beginning, whence the 2k – 1 ampersands. Here, in the first column, the alignment happens at the left margin, and using && means the beginning of the second column and its alignment point are at the same place. – Bernard Jul 6 '17 at 15:36
  • How can I achieve centering or right-alignment then? Isn't that syntax ambiguous when it comes to those cases? Could you explain how I can achieve the first column to be centered and the second one to be left-aligned? – a_guest Jul 7 '17 at 8:24
  • @a_guest: I added a code for these cases. Only the centred/left-aligned case requires a different syntax, using gathered and aligned. – Bernard Jul 7 '17 at 8:49
  • Thanks! However I don't get the hang of the second example (right-alignment). The syntax is && 1st && 2nd &, so the first column is preceded by && while the second column is preceded by only & (the second ampersand indicating a new column) but includes a trailing &. Despite this difference the alignment in both columns is the same. Why is this? Also this examples uses five & for two alignment points which is not 2k-1 as you pointed out in your previous comment. I'd like to understand the align syntax so I can apply it to general cases. – a_guest Jul 7 '17 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.