6

Firstly, sorry for my english level, I'm French. Secondly, I've read eqnarray environment becomes obsolete, and we have to replace this by align. Ok, but it's not satisfying for me. I explain :

\documentclass[12pt]{article}
\usepackage{amsmath,amsfonts,amssymb} % Tableaux, maths
\usepackage[frenchb]{babel}
\usepackage[top=1.5cm,bottom=1.5cm,right=1.5cm,left=1.5cm]{geometry} % Marges
\begin{document}
\begin{eqnarray*}
  Test~eqnarray*   & = & \text{Good alignment} \\
  & Because & \text{the text is aligned near to the equal sign}
\end{eqnarray*}
\end{document}

gives this :

With the environment align

\documentclass[12pt]{article}
\usepackage{amsmath,amsfonts,amssymb} % Tableaux, maths
\usepackage[frenchb]{babel}
\usepackage[top=1.5cm,bottom=1.5cm,right=1.5cm,left=1.5cm]{geometry} % Marges
\begin{document}
\begin{align*}
  Test~align*   & = & \text{Bad alignment} \\
  & Because & \text{the text is right-aligned, far to the equal sign}
\end{align*}
\end{document}

gives :

enter image description here

How can I obtain absolutly the same results as eqnarray with align ?

Note : I don't care the spacing problem with eqnarray

9
  • Is \begin{align*} Test~align* & = \text{Bad alignment} \\ & = \text{Because the text is aligned near to the equal sign} \end{align*} OK for you or do you want the excessive space around the equal sign?
    – moewe
    Commented Dec 8, 2018 at 14:11
  • No the spacing is ok here, but as said below, I want to aligne Because with =
    – Alex
    Commented Dec 8, 2018 at 14:29
  • In that case it might make sense to change the eqnarray* example to show that as well. At first glance your question read as if you wanted to align two =s.
    – moewe
    Commented Dec 8, 2018 at 14:31
  • I want to align both = (centered) and the text after (left-aligned)
    – Alex
    Commented Dec 8, 2018 at 14:33
  • But doesn't \begin{align*} Test~align* & = \text{Bad alignment} \\ & = \text{Because the text is aligned near to the equal sign} \end{align*} do more or less that if both lines contain a =? If not, then the alignment would be different, of course.
    – moewe
    Commented Dec 8, 2018 at 14:35

2 Answers 2

7

You have to understand that in align and similar amsmath environments, if you want n alignment groups, each group except the first requires 2 ampersands: the first & introduces a new alignment group, and the second & specifies the alignment point inside this group. The first group doesn't require the first ampersand, of course, so n alignment groups in all require 2 n – 1 &s.

You have used the eqnarray syntax, with two &, so amsmath understands there are two groups. As there's no & for the alignment point in the second group, it is aligned on the last characters of each line.

Added:

An easy solution to your problem is obtained with the eqparbox package. Incidentally, I simplified your code for geometry (since all your margins are equal you can simply set margin =). Also, the frenchb option is ibsolete, and should be replaced with french, preferable loaded with the \documentclass, so that all language-dependent packages be informed. Lastn needless to load amsfonts, since amssymb does it for you.

\documentclass[12pt, french]{article}
\usepackage{amsmath,amssymb} % Tableaux, maths
\usepackage{babel}
\usepackage[margin=1.5cm]{geometry} % Marges
\usepackage{eqparbox}
\newcommand{\eqrel}[2][B]{\mathrel{\eqmakebox[#1]{#2}}} %% eqparbox uses a system of tags, which is the optional argument here – defaults to B.

\begin{document}

\begin{align*}
  \emph{Test~align*} &\eqrel{$=$} \text{Bad alignment} \\
  &\eqrel{\em Because} \text{the text is left-aligned, near the equal sign}
\end{align*}

\end{document} 

enter image description here

8
  • Ok thank you it's interesting, even if I don't success to have that I want for now
    – Alex
    Commented Dec 8, 2018 at 14:40
  • You want because to be aligned with the = sign?
    – Bernard
    Commented Dec 8, 2018 at 14:43
  • Yes, and the text in the first line left-aligned with the text in the second line (see my changed MWE)
    – Alex
    Commented Dec 8, 2018 at 14:45
  • It is a solution yes, not very practical but I can enumerate my equations. Thank you for your help
    – Alex
    Commented Dec 8, 2018 at 15:16
  • I've defined an, \eqrel command to simplify typing.
    – Bernard
    Commented Dec 8, 2018 at 15:36
6

in align you have one ampersand to much:

\documentclass[12pt]{article}
\usepackage{amsmath,amsfonts,amssymb} % Tableaux, maths
\usepackage[frenchb]{babel}
\usepackage[top=1.5cm,bottom=1.5cm,right=1.5cm,left=1.5cm]{geometry} % Marges
\begin{document}
\begin{align*}
  Test~align*   & = \text{Bad alignment} \\
  Because       & = \text{the text is right-aligned, far to the equal sign}
\end{align*}
or 
\begin{align*}
  Test~align*   & = \text{Bad alignment} \\
                & \text{Because the text is right-aligned, far to the equal sign}
\end{align*}
or 
\begin{align*}
  Test~align*   & = \parbox[t]{0.4\linewidth}{
                    Bad alignment \\
                    Because the text is right-aligned, far to the equal sign}
\end{align*}
\end{document}

enter image description here

adedndum: apparently you looking for the following:

enter image description here

\documentclass[12pt]{article}
\usepackage{amsmath} 

\begin{document}
\[\setlength\arraycolsep{2pt}
\begin{array}{rcl}
  Test~array    & =         & \text{Fine alignment}\\
                & Because   & \text{the text is left-aligned \dots}
\end{array}
\]
\end{document}

addendum (2): with help of very old (and almost forgotten) package mathenv from mfwtools:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{mathenv}
\usepackage[frenchb]{babel}
\usepackage[top=1.5cm,bottom=1.5cm,right=1.5cm,left=1.5cm]{geometry} % Marges

\begin{document}
\begin{eqnarray}[rc@{\;}l]
  Test~eqnarray &   =     & \text{Good alignment} \\
                & Because & \text{the text is aligned near to the equal sign}
\end{eqnarray}
\end{document}

enter image description here

11
  • Thank you, but I want Because to be aligned with =. Is this possible ?
    – Alex
    Commented Dec 8, 2018 at 14:20
  • @Alex, of course. you just need to place ampersand before Because if you like to have it below right text
    – Zarko
    Commented Dec 8, 2018 at 14:23
  • Sorry, I've changed my MWE to reveal better that I want
    – Alex
    Commented Dec 8, 2018 at 14:40
  • @Alex, this is not possible to achieve with align, but with array is simple. see addendum to answer.
    – Zarko
    Commented Dec 8, 2018 at 14:57
  • Yes it's perfect. But I can't enumerate my equations if necessary... Can I ?
    – Alex
    Commented Dec 8, 2018 at 15:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .