3

I've seen this https://stackoverflow.com/questions/2632628/left-align-block-of-equations answer as well as a handful of others, but none of them gives a satisfactory solution.

The problem

Two equations need to be aligned such that equals signs are positioned one under another, and the text on the left side of the equals sign is aligned to the left.

What I tried so far

  • \documentclass[fleqn] - this never aligns the test to the right of the last ampersand to the left.

  • \begin{flalign} - same as above.

  • \begin{tabular}{lll} inside \beign{equation} - it's possible to achieve proper layout, but is very cumbersome (I need to wrap all formulas inside in $$ and such, which makes referencing difficult.


Example

% Created 2015-01-10 Sat 16:22
\documentclass[fleqn]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage[utf8]{inputenc}
\author{wvxvw}
\date{\today}
\title{test}
\hypersetup{
  pdfkeywords={},
  pdfsubject={},
  pdfcreator={Emacs 25.0.50.1 (Org mode 8.2.2)}}
\begin{document}

\maketitle
\tableofcontents


\section{Problem 1}
\label{sec-1}
\begin{align*}
  U &=& \mathrm{Sp} \{ x^3 + 4x^2 - x + 3, x^3 + 5x^2 + 5, 3x^3 + 10x^2 + 5 \} & \\
  W &=& \mathrm{Sp} \{ x^3 + 4x^2 + 6, x^3 + 2x^2 - x + 5, 2x^3 + 2x^2 - 3x + 9 \} &
\end{align*}
% Emacs 25.0.50.1 (Org mode 8.2.2)
\end{document}

I tried moving & to different positions, this example only shows one combination.

4
  • align is not eqnarray: you just need &=; remove the trailing &. Unrelated: you should define \DeclareMathOperator{\Sp}{Sp} in the preamble and use \Sp instead of \mathrm{Sp}; \tolerance=1000 seems quite high.
    – egreg
    Commented Jan 10, 2015 at 14:41
  • @egreg Oh, I was searching for \DeclareMathOperator, just couldn't remember what the command was! Thanks a lot. Re' &= - sorry, no, that gives ugly spaces on the right of the equals sign and the rest of the equation is aligned to the right... \tolerance and other \usepackage commands are generated by Emacs. I might be able to tweak it, but I don't know yet what it does, so I'll probably let it be for now.
    – wvxvw
    Commented Jan 10, 2015 at 14:44
  • 1
    Ugly spaces? I see them if &=& is used, not with &= (see this picture). I've never seen the left hand side left aligned, in cases like this.
    – egreg
    Commented Jan 10, 2015 at 14:49
  • @egreg Sorry, you are right, I confused several documents I made to test it. Yes, &= gives the result I wanted. Technically, this can be the answer.
    – wvxvw
    Commented Jan 10, 2015 at 14:52

2 Answers 2

5

You are using the syntax of eqnarray for the alignment of the relations. The correct syntax is &=.

If you really want the left hand sides to be left aligned, you can use alignat, but I don't think it will give a good result.

In the example, I'll leave only the necessary packages (amsmath).

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

\DeclareMathOperator{\Sp}{Sp}

\begin{document}

\section{Problem 1}
\label{sec-1}

Normal way is with the left hand side right aligned as follows
\begin{align*}{2}
  U &= \Sp \{ x^3 + 4x^2 - x + 3, x^3 + 5x^2 + 5, 3x^3 + 10x^2 + 5 \} \\
  W &= \Sp \{ x^3 + 4x^2 + 6, x^3 + 2x^2 - x + 5, 2x^3 + 2x^2 - 3x + 9 \}
\end{align*}
but if you want them left aligned, use \texttt{alignat}:
\begin{alignat*}{2}
  &U &&= \Sp \{ x^3 + 4x^2 - x + 3, x^3 + 5x^2 + 5, 3x^3 + 10x^2 + 5 \} \\
  &W &&= \Sp \{ x^3 + 4x^2 + 6, x^3 + 2x^2 - x + 5, 2x^3 + 2x^2 - 3x + 9 \}
\end{alignat*}
Choose your way, but be consistent in your document.

\end{document}

enter image description here

Note the definition of \Sp that ensures better spacing.

2

Two suggestions:

  • Since you're using an align* environment, use &= rather than &=& to align the equations on the = symbols.

  • While you're at it, do also omit the trailing & characters at the end of each equation.

  • Issue the instruction \DeclareMathOperator{\Sp}{Sp} in the preamble (after loading amsmath); this will simplify the code writing in the body of the text.

The following code implements these thoughts while reducing your code to the bare minimum.

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[fleqn]{amsmath}
\DeclareMathOperator{\Sp}{Sp}
\begin{document}
\begin{align*}
U &= \Sp \{ x^3 + 4x^2 - x + 3, x^3 + 5x^2 + 5, 3x^3 + 10x^2 + 5 \} \\
W &= \Sp \{ x^3 + 4x^2 + 6, x^3 + 2x^2 - x + 5, 2x^3 + 2x^2 - 3x + 9 \} 
\end{align*}
\end{document}

You must log in to answer this question.

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