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?

a_guest
  • 351

1 Answers1

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

a_guest
  • 351
Bernard
  • 271,350
  • 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 06 '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 06 '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 07 '17 at 08: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 07 '17 at 08: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 07 '17 at 09:12
  • The normal structure of an flalign environment is 3 columns, hence 5 &. The second example indeed has 3 columns, but the first column has something in it only in the first row (Some stuff...), and its length is 0, due to \rlap. In the other rows, it's empty. So the right-aligned left column is really the second column, and the right column is the third. The trailing & is the alignment point just after the last word (hence it is right-aligned); strictly speaking, this one can be deleted, but I left it to make the structure more visible. Is that clearer? – Bernard Jul 07 '17 at 09:32
  • So is it correct that for each & beyond the first one, even ones move on to the next column and odd ones determine the alignment in the respective column (while the first & determines the alignment in the first column)? However absence of any & seems to apply centering. Trying just content centers the content. Using content & also centers the content (while I expected right-alignment of the first (and only) column). Using content && left-aligns the content (while I expected right-alignment again). Is there any documentation which defines the rules for parsing &-syntax? – a_guest Jul 07 '17 at 11:51
  • A simple align environment with several lines, without any & is right-aligned, and the whole block is centred. I know only amsldoc.pdf and studied carefully the examples in §3.6, experimenting a little to check if I understood well the ins and the outs of alignment. – Bernard Jul 07 '17 at 12:04