LaTeX forum ⇒ Math & ScienceWhat's wrong with this small equation ?

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

What's wrong with this small equation ?

Postby Cham » Mon Apr 25, 2011 3:16 am

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:
  1. \begin{equation}
  2. \epsilon_{ijk} = \left\{
  3. \begin{align}
  4. 1 \quad & \text{si $ijk$ est une permutation paire de $123$,} \\
  5. -1 \quad & \text{si $ijk$ est une permutation impaire de $123$,} \\
  6. 0 \quad & \text{si deux indices sont égaux.}
  7. \end{align}
  8. \right.
  9. \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.

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

Postby svend_tveskaeg » Mon Apr 25, 2011 9:58 am

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: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Mon Apr 25, 2011 10:41 am

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.
  1. \documentclass[11pt,a4paper]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage{mathtools} % loads »amsmath«
  5.  
  6. \newcommand*{\pmm}{\phantom{\mathrel{-}}}
  7.  
  8. \begin{document}
  9. \begin{equation}
  10. \epsilon_{ijk}=
  11. \begin{cases}
  12. \pmm 1 \quad & \text{si $ijk$ est une permutation paire de $123$,} \\
  13. -1 \quad & \text{si $ijk$ est une permutation impaire de $123$,} \\
  14. \pmm 0 \quad & \text{si deux indices sont égaux.}
  15. \end{cases}
  16. \end{equation}
  17. \end{document}



Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

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

Postby Cham » Mon Apr 25, 2011 4:14 pm

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: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Mon Apr 25, 2011 8:53 pm

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.
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

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

Postby Cham » Mon Apr 25, 2011 10:25 pm

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.

  1. \begin{equation}
  2. P_{321} =
  3. \begin{bmatrix}
  4. \pmm 1 & \pmm 0 & \pmm 0 \pmm \\
  5. \pmm 0 & \pmm 1 & \pmm 0 \pmm \\
  6. \pmm 0 & \pmm 0 & -1\pmm
  7. \end{bmatrix}\!\!\!
  8. \begin{bmatrix}
  9. \pmm 0 & \pmm 0 & \pmm 1 \pmm \\
  10. \pmm 0 & \pmm 1 & \pmm 0 \pmm \\
  11. -1 & \pmm 0 & \pmm 0 \pmm
  12. \end{bmatrix}
  13. \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: 9601
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Mon Apr 25, 2011 10:59 pm

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: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Tue Apr 26, 2011 7:19 pm

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.
  1. \documentclass[11pt,a4paper]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage{mathtools}
  5. \usepackage{array}
  6.  
  7. \newcommand*{\pmm}{\phantom{\mathrel{-}}}
  8. \newcolumntype{P}{>{\pmm}r}
  9.  
  10. \begin{document}
  11. \begin{equation}
  12. P_{321} =
  13. \begin{bmatrix}
  14. \pmm 1 & \pmm 0 & \pmm 0 \pmm \\
  15. \pmm 0 & \pmm 1 & \pmm 0 \pmm \\
  16. \pmm 0 & \pmm 0 & -1\pmm
  17. \end{bmatrix}\!\!\!
  18. \begin{bmatrix}
  19. \pmm 0 & \pmm 0 & \pmm 1 \pmm \\
  20. \pmm 0 & \pmm 1 & \pmm 0 \pmm \\
  21. -1 & \pmm 0 & \pmm 0 \pmm
  22. \end{bmatrix}
  23. \end{equation}
  24.  
  25. \begin{equation}
  26. P_{321} =
  27. \begin{bmatrix*}[r]
  28. 1 & 0 & 0 \\
  29. 0 & \pmm 1 & 0 \\
  30. 0 & 0 & -1
  31. \end{bmatrix*}\!\!\!
  32. \begin{bmatrix*}[r]
  33. 0 & 0 & \pmm 1 \\
  34. 0 & \pmm 1 & 0 \\
  35. -1 & 0 & 0
  36. \end{bmatrix*}
  37. \end{equation}
  38.  
  39. \begin{equation}
  40. P_{321} =
  41. \left[
  42. \begin{array}{rPr}
  43. 1 & 0 & 0 \\
  44. 0 & 1 & 0 \\
  45. 0 & 0 & -1
  46. \end{array}
  47. \right]\!\!\!
  48. \left[
  49. \begin{array}{rPP}
  50. 0 & 0 & 1 \\
  51. 0 & 1 & 0 \\
  52. -1 & 0 & 0
  53. \end{array}
  54. \right]
  55. \end{equation}
  56. \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.
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

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

Postby Cham » Tue Apr 26, 2011 9:50 pm

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. :)


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 5 guests