Math & ScienceWhat's wrong with this small equation ?

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

What's wrong with this small equation ?

Post by Cham »

I'm getting a compilation error with this small equation, and I don't know why. What is wrong here ? Of course, the problem isn't in the preambule. All the document is compiling fine, except for the following equation:

Code: Select all

	\begin{equation}
		\epsilon_{ijk} = \left\{
			\begin{align}
				1 \quad & \text{si $ijk$ est une permutation paire de $123$,} \\
				-1 \quad & \text{si $ijk$ est une permutation impaire de $123$,} \\
				0 \quad & \text{si deux indices sont égaux.}
			\end{align}
		\right.
	\end{equation}
Any idea ?

I already know the cases environment, but I need the 1, -1 and 0 to be aligned to their right.
Last edited by Cham on Wed Apr 27, 2011 6:55 pm, edited 3 times 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.

svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

What's wrong with this small equation ?

Post by svend_tveskaeg »

A MWE is still needed! Otherwise we cannot compile and try to figure out the error and/or a solution.

By looking at the source code, though, I thing the problem is that you have \left\{ but no \right equivalence. Furthermore, an \align environment and an \equation environment cannot be used together (I think).
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

What's wrong with this small equation ?

Post by localghost »

It has already been mentioned that you can't nest these two environments. Replace »align« with »aligned« and it should work.
Cham wrote:[…] I already know the cases environment, but I need the 1, -1 and 0 to be aligned to their right.
With a little helper macro you can get the desired alignment.

Code: Select all

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

\newcommand*{\pmm}{\phantom{\mathrel{-}}}

\begin{document}
  \begin{equation}
    \epsilon_{ijk}=
    \begin{cases}
      \pmm 1 \quad & \text{si $ijk$ est une permutation paire de $123$,} \\
      -1 \quad & \text{si $ijk$ est une permutation impaire de $123$,} \\
       \pmm 0 \quad & \text{si deux indices sont égaux.}
    \end{cases}
  \end{equation}
\end{document}

Thorsten
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

What's wrong with this small equation ?

Post by Cham »

Thanks a lot, Thorsten. Both solutions are working perfectly ! :-)

EDIT : The macro above also solves a small alignment problem I had with matrices. Great ! Thanks again !
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

What's wrong with this small equation ?

Post by localghost »

Cham wrote:[…] The macro above also solves a small alignment problem I had with matrices. Great ! Thanks again !
For matrices the mathtools package offers appropriate solutions. You can learn more about math typesetting in the »Math mode« document.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

What's wrong with this small equation ?

Post by Cham »

localghost wrote: For matrices the mathtools package offers appropriate solutions. You can learn more about math typesetting in the »Math mode« document.
Can you be more specific with the following example ? Lets suppose we want a 3 x 3 matrix with some positive and negative numbers. We would want all numbers to be well aligned, and an equal spacing between each column. Currently, using the macro given above, I wrote the following matrix and it's looking great once compiled.

Code: Select all

	\begin{equation}
		P_{321} =
		\begin{bmatrix}
			\pmm 1 & \pmm 0 & \pmm 0 \pmm \\
			\pmm 0 & \pmm 1 & \pmm 0 \pmm  \\
			\pmm 0 & \pmm 0 & -1\pmm 
		\end{bmatrix}\!\!\!
		\begin{bmatrix}
			\pmm 0 & \pmm 0 & \pmm 1 \pmm  \\
			\pmm 0 & \pmm 1 & \pmm 0 \pmm \\
			-1 & \pmm 0 & \pmm 0 \pmm
		\end{bmatrix}
	\end{equation}
where the new command \pmm adds an invisible "-". Do you have a better (cleaner) solution, using the mathtools package ?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10337
Joined: Mon Mar 10, 2008 9:44 pm

What's wrong with this small equation ?

Post by Stefan Kottwitz »

Hi Cham,

regarding more customizable matrices, have a look here: An extension to amsmath matrix environments. The solution there offers customizable alignment and more.

Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

What's wrong with this small equation ?

Post by localghost »

The solution with the bmatrix* environment of mathtools is not as good as I thought. Even with a slightly tweaked array environment you get better results.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{array}

\newcommand*{\pmm}{\phantom{\mathrel{-}}}
\newcolumntype{P}{>{\pmm}r}

\begin{document}
  \begin{equation}
    P_{321} =
    \begin{bmatrix}
      \pmm 1 & \pmm 0 & \pmm 0 \pmm \\
      \pmm 0 & \pmm 1 & \pmm 0 \pmm  \\
      \pmm 0 & \pmm 0 & -1\pmm
    \end{bmatrix}\!\!\!
    \begin{bmatrix}
      \pmm 0 & \pmm 0 & \pmm 1 \pmm  \\
      \pmm 0 & \pmm 1 & \pmm 0 \pmm \\
      -1 & \pmm 0 & \pmm 0 \pmm
    \end{bmatrix}
  \end{equation}

  \begin{equation}
    P_{321} =
    \begin{bmatrix*}[r]
      1 & 0 & 0 \\
      0 & \pmm 1 & 0  \\
      0 & 0 & -1
    \end{bmatrix*}\!\!\!
    \begin{bmatrix*}[r]
      0 & 0 & \pmm 1 \\
      0 & \pmm 1 & 0  \\
      -1 & 0 & 0
    \end{bmatrix*}
  \end{equation}

  \begin{equation}
    P_{321} =
    \left[
    \begin{array}{rPr}
      1 & 0 & 0 \\
      0 & 1 & 0  \\
      0 & 0 & -1
    \end{array}
    \right]\!\!\!
    \left[
    \begin{array}{rPP}
      0 & 0 & 1 \\
      0 & 1 & 0  \\
      -1 & 0 & 0
    \end{array}
    \right]
  \end{equation}
\end{document}
But none of these solutions is really satisfactory. For example, with the array environment you have to take care that you only use the new »P« column type in columns without a minus sign. But at least you don't have to insert the invisible minus sign explicitly. In the bmatrix* environment at least one element in a column without any minus sign needs a \pmm command to get the right appearance. And the distance between matrix elements and enclosing brackets seems too narrow. So these can only be partial solutions. But the method with array seems to be the simplest. The final choice is up to.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: What's wrong with this small equation ?

Post by Cham »

Thanks localghost. Your code given above is confirming what I thought. So the solution I gave is the most appropriate one for my personal taste (better global appearance of the matrix equation).

In any cases, the problem I exposed in the first message (when I started the topic) is completely solved now.

Thanks again for all of your help. :)
Post Reply