# Trouble using flalign for left aligned math equations

I tried to left align some equations, but always get the wrong result

Code below

\documentclass[a4paper]{article}
\usepackage[fleqn]{amsmath}
\usepackage{showframe}
\begin{document}
\section*{Test}

\begin{flalign}
&&U_{i}&&= U_{\mathrm{h}i} + U_{\mathrm{r}i} \ ,  &&I_{i} &&= \frac{1}{Z_{\mathrm{L}i}}(U_{\mathrm{h}i} - U_{\mathrm{r}i})\\
&&U_{\mathrm{h}i}&&= \frac{U_i + Z_{\mathrm{L}i}I_{i}}{2} \ , &&U_{\mathrm{r}i} &&= \frac{U_i - Z_{\mathrm{L}i}I_{i}}{2}
\end{flalign}

\end{document}


What I would like to have:

Thank you all

• Why flalign? Any reason? – Werner Oct 5 '18 at 17:22
• @Werner I seached some method before. flalign align alignat I have all tried – sun0727 Oct 5 '18 at 17:28
• why do you want to left align the left hand side of the =??? so making the space around the = asymmetrical? that looks very odd and quite unlike a normal left aligned equation setting in amsmath. – David Carlisle Oct 5 '18 at 18:01
• @DavidCarlisle May be not good for Quality. But it is true a trouble for me. In my opinion, & split the equation and each part should be left aligned – sun0727 Oct 5 '18 at 18:08
• it makes it harder to read (and distracts the reader with an unusual layout) but it's your document and a free world, if that's what you what I see egreg and Werner have provided solutions:-) – David Carlisle Oct 5 '18 at 18:35

You can just use flalign with & around the alignment relations and between each of the equations as well as a final & on each row:

\documentclass{article}

\usepackage{amsmath,eqparbox,xparse}

% https://tex.stackexchange.com/a/34412/5764
\makeatletter
\NewDocumentCommand{\eqmathbox}{o O{c} m}{%
\IfValueTF{#1}
{\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}}
{\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}}
\mathpalette\eqmathbox@{#3}
}
\makeatother

\begin{document}

\begin{flalign}
\eqmathbox[L1][l]{U_i} &= U_{\mathrm{h}i} + U_{\mathrm{r}i},  &
\eqmathbox[L2][l]{I_i} &= \frac{1}{Z_{\mathrm{L}i}}(U_{\mathrm{h}i} - U_{\mathrm{r}i}) & \\
\eqmathbox[L1][l]{U_{\mathrm{h}i}} &= \frac{U_i + Z_{\mathrm{L}i}I_{i}}{2}, &
\eqmathbox[L2][l]{U_{\mathrm{r}i}} &= \frac{U_i - Z_{\mathrm{L}i}I_{i}}{2} &
\end{flalign}

\end{document}


The use of eqparbox supports alignment choices for elements within \eqmathbox[<tag>][<align>]{<stuff>}. All elements with the same <tag> will have the same maximum width where you can specify the individual <align>ment as needed (left in the above example).

An alternative without eqparbox:

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\begin{flalign}
\mathrlap{U_i}\phantom{U_{\mathrm{h}i}} &= U_{\mathrm{h}i} + U_{\mathrm{r}i},  &
\mathrlap{I_i}\phantom{U_{\mathrm{r}i}} &= \frac{1}{Z_{\mathrm{L}i}}(U_{\mathrm{h}i} - U_{\mathrm{r}i}) & \\
U_{\mathrm{h}i} &= \frac{U_i + Z_{\mathrm{L}i}I_{i}}{2}, &
U_{\mathrm{r}i} &= \frac{U_i - Z_{\mathrm{L}i}I_{i}}{2} &
\end{flalign}

\end{document}

• thanks for the answer, but I also need the equation begin from left, not centered – sun0727 Oct 5 '18 at 17:29
• @sun0727: Like which of the following two setups: image Equations (1) & (2) or equations (3) & (4)? – Werner Oct 5 '18 at 17:34
• like the second one, but Ui shoule also at the line begin, so the space betwenn Ui and = can be more. – sun0727 Oct 5 '18 at 17:37
• thanks, I have uploaded a figure for what I want to have. – sun0727 Oct 5 '18 at 17:47
• @sun0727: See the update. – Werner Oct 5 '18 at 17:57

I can see no reason for the equation to start at the left margin. Anyway, here's the code

\documentclass[a4paper]{article}
\usepackage[fleqn]{amsmath}
\usepackage{showframe}

\begin{document}

\section*{Test}

\begin{flalign}
U_{i}           &= U_{\mathrm{h}i} + U_{\mathrm{r}i} ,
& I_{i} &= \frac{1}{Z_{\mathrm{L}i}}(U_{\mathrm{h}i} - U_{\mathrm{r}i}) && \\
U_{\mathrm{h}i} &= \frac{U_i + Z_{\mathrm{L}i}I_{i}}{2} ,
& U_{\mathrm{r}i} &= \frac{U_i - Z_{\mathrm{L}i}I_{i}}{2} &&
\end{flalign}

\end{document}


With the standard align:

\documentclass[a4paper]{article}
\usepackage[fleqn]{amsmath}
\usepackage{showframe}

\begin{document}

\section*{Test}

\begin{align}
U_{i}           &= U_{\mathrm{h}i} + U_{\mathrm{r}i} ,
& I_{i} &= \frac{1}{Z_{\mathrm{L}i}}(U_{\mathrm{h}i} - U_{\mathrm{r}i}) \\
U_{\mathrm{h}i} &= \frac{U_i + Z_{\mathrm{L}i}I_{i}}{2} ,
& U_{\mathrm{r}i} &= \frac{U_i - Z_{\mathrm{L}i}I_{i}}{2}
\end{align}

\end{document}


You get

which agrees with all other equations, since you're using fleqn.

If your aim is to align to the left U and I, then use a phantom. I took the occasion for simplifying your input by defining \rh, \rr and \rL. The macro \prh stands for “a phantom \rh”.

\documentclass[a4paper]{article}
\usepackage[fleqn]{amsmath}
\usepackage{showframe}

\newcommand{\rh}{\mathrm{h}}
\newcommand{\prh}{\hphantom{\rh}}
\newcommand{\rL}{\mathrm{L}}
\newcommand{\rr}{\mathrm{r}}

\begin{document}

\section*{Test}

\begin{align}
U_{i\prh}           &= U_{\rh i} + U_{\rr i} ,
& I_{i\prh} &= \frac{1}{Z_{\rL i}}(U_{\rh i} - U_{\rr i}) \\
U_{\rh i} &= \frac{U_i + Z_{\rL i}I_{i}}{2} ,
& U_{\rh i} &= \frac{U_i - Z_{\rL i}I_{i}}{2}
\end{align}

\end{document}


Adapt to the flalign shown above, if you prefer.

• thanks, I have uploaded a figure for what I want to have. – sun0727 Oct 5 '18 at 17:47
• @sun0727 I don't think it improves the quality. But I added it. – egreg Oct 5 '18 at 17:55

The flalign environment requires only 5 = 2×3 – 1 ampersands since it has 3 groups of alignment.

Another possibility, to left align only some equations in your document; consists in nesting your equations in a fleqn environment, defined by nccmath. Furthermore, it can take an optional argument for the distance from the left margin at which the equation body begins (by default, it is 0pt). Demo:

\documentclass[a4paper]{article}
\usepackage{amsmath, nccmath}
\usepackage{showframe}
\renewcommand{\ShowFrameLinethickness}{0.3pt}

\begin{document}
\section*{Test}

\begin{flalign}
U_{i}&= U_{\mathrm{h}i} + U_{\mathrm{r}i} &I_{i} &= \frac{1}{Z_{\mathrm{L}i}}(U_{\mathrm{h}i} - U_{\mathrm{r}i}) & \\
U_{\mathrm{h}i}&= \frac{U_i + Z_{\mathrm{L}i}I_{i}}{2}&U_{\mathrm{r}i}&= \frac{U_i - Z_{\mathrm{L}i}I_{i}}{2}
\end{flalign}
\vspace{\baselineskip}
\begin{fleqn}[1em]
\begin{align}
U_{i}&= U_{\mathrm{h}i} + U_{\mathrm{r}i} &I_{i} &= \frac{1}{Z_{\mathrm{L}i}}(U_{\mathrm{h}i} - U_{\mathrm{r}i}) & \\
U_{\mathrm{h}i}&= \frac{U_i + Z_{\mathrm{L}i}I_{i}}{2}&U_{\mathrm{r}i}&= \frac{U_i - Z_{\mathrm{L}i}I_{i}}{2}
\end{align}
\end{fleqn}

\end{document}