Math & ScienceAlignment of a multi-line Formula

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
erotavlas
Posts: 19
Joined: Thu Aug 04, 2011 3:53 pm

Alignment of a multi-line Formula

Post by erotavlas »

Hi,

I have a problem with the alignment of a multi-line formula. I have tried to use the command \eqnarray*{} or \align{}, but each line of the formula is aligned to the right side of the page instead on the left. Why?

Code: Select all

\begin{eqnarray*}
\textrm{forall x} \\
 f(x) &= (x+a)(x+b) \\
 &= x^2 + (a+b)x + ab \\
\{\textrm{MYFORMULA}\}
\end{eqnarray*}
or

Code: Select all

\begin{align*}
 f(x) &= (x+a)(x+b) \\
 &= x^2 + (a+b)x + ab
\end{align*}
Thank you
Last edited by erotavlas on Sat Aug 06, 2011 6:02 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Alignment of a multi-line Formula

Post by localghost »

Somehow I can't comprehend the problem.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}    % loads »amsmath«

\begin{document}
  \begin{align*}
    f(x) &= (x+a)(x+b) \\
    &= x^2 + (a+b)x + ab
  \end{align*}
\end{document}

Thorsten
erotavlas
Posts: 19
Joined: Thu Aug 04, 2011 3:53 pm

Alignment of a multi-line Formula

Post by erotavlas »

Thank you for your fast reply. Your code is ok.
My problem is with the following code

Code: Select all

\begin{align*}
\underbrace{\forall x \ldots \exists z}_{\textrm{Quantified Portion}} \\
\underbrace{[([\neg] P_1(x) \vee \ldots \vee [\neg] P_2(z)) \wedge \ldots \wedge ([\neg] P_i(x) \vee [\neg] P_n(z))]}_{\textrm{Quantifier-free part \ - \ CNF expression}}; \\
\{\textrm{FOL Formula}\}
\end{align*}
Is it not aligned on the left, why?

Thank
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Alignment of a multi-line Formula

Post by localghost »

A remark beforehand. It makes no sense to post working code that does not reproduce the described problem. This is misleading. Instead you should post a minimal example that reproduces the undesired behaviour clearly and is compilable out of the box for everybody.

The align(*) environment is usually used to align parts of equations around relational operators like "=", ">" or "<". The part before is right aligned and the part behind is left aligned. Alignment is done by the ampersand ("&"), the so called alignment character. In your case this means that every line of your expression has to be started with an ampersand.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}    % loads »amsmath«

\begin{document}
  \begin{align*}
    & \underbrace{\forall x \ldots \exists z}_{\textrm{Quantified Portion}} \\
    & \underbrace{[([\neg] P_1(x) \vee \ldots \vee [\neg] P_2(z)) \wedge \ldots \wedge ([\neg] P_i(x) \vee [\neg] P_n(z))]}_{\textrm{Quantifier-free part \ - \ CNF expression}}; \\
    & \{\textrm{FOL Formula}\}
  \end{align*}
\end{document}
More about math typesetting in the excellent »Math mode« document.
erotavlas
Posts: 19
Joined: Thu Aug 04, 2011 3:53 pm

Re: Alignment of a multi-line Formula

Post by erotavlas »

Ok, thank you.
Post Reply