Math & ScienceAlignment problem with split

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
jjhall
Posts: 2
Joined: Wed Feb 04, 2009 7:30 am

Alignment problem with split

Post by jjhall »

Hello, I am having a problem getting an equation aligned properly using align and split. The equation doesn't fit on one line, so after much searching I found that using the split environment is the way to go. However, the left hand side of the equation is now lining up between the two lines on the right. Also, the first segment and last segment of the right hand side are not aligned vertically. I am pretty sure I am doing this incorrectly, since I have not used split before.

Code: Select all

\begin{align}
x_{i,j}  & = \begin{split} \left\{\frac{a}{(\Delta\xi)^2}\left(x_{i+1,j}+
  x_{i-1,j}\right) + \frac{c}{(\Delta\eta)^2}
  \left(x_{i,j+1}+x_{i,j-1}\right){} \right.\\ 
  \left. {}- \frac{b}{2\Delta\xi\Delta\eta}\left(x_{i+1,j+1}-x_{i+1,j-1}
  -x_{i-1,j+1}+x_{i-1,j-1}\right) \right\}/2\left[\frac{a}{(\Delta\xi)^2}+
    \frac{c}{(\Delta\eta)^2}\right] \end{split}
\end{align}
FYI, I am not exactly a newbie, but I am also far from being a LaTeX expert.

Thanks,
Jeremiah

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 problem with split

Post by localghost »

You can put the alignment character (&) directly into the split environment to get the split lines aligned to the equal sign.

Code: Select all

\begin{align}
  x_{i,j}=
  \begin{split}
    &\left\{\frac{a}{(\Delta\xi)^2}\left(x_{i+1,j}+x_{i-1,j}\right)+\frac{c}{(\Delta\eta)^2}\left(x_{i,j+1}+x_{i,j-1}\right){} \right.\\
    &\left.-\frac{b}{2\Delta\xi\Delta\eta}\left(x_{i+1,j+1}-x_{i+1,j-1}-x_{i-1,j+1}+x_{i-1,j-1}\right)\right\}/2\left[\frac{a}{(\Delta\xi)^2}+\frac{c}{(\Delta\eta)^2}\right]
  \end{split}
\end{align}

Best regards and welcome to the board
Thorsten¹
jjhall
Posts: 2
Joined: Wed Feb 04, 2009 7:30 am

Re: Alignment problem with split

Post by jjhall »

Thanks! That worked. Now how do I get the left hand side to line up with the top row of the right hand side?

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

Alignment problem with split

Post by localghost »

jjhall wrote:[…] Now how do I get the left hand side to line up with the top row of the right hand side? […]
At first I was a little bit astonished about your answer because it worked as desired when I copied the environment into an existing document. So I built a minimal working example (MWE) and got the same output as you with an alignment of the left side to the middle of the right side. Then I remembered that I have to include amsmath with an option.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[margin=2cm]{geometry}
\usepackage[tbtags]{amsmath}

\begin{document}
  \begin{align}
    x_{i,j}=
    \begin{split}
      &\left\{\frac{a}{(\Delta\xi)^2}\left(x_{i+1,j}+x_{i-1,j}\right)+\frac{c}{(\Delta\eta)^2}\left(x_{i,j+1}+x_{i,j-1}\right){} \right.\\
      &\left.-\frac{b}{2\Delta\xi\Delta\eta}\left(x_{i+1,j+1}-x_{i+1,j-1}-x_{i-1,j+1}+x_{i-1,j-1}\right)\right\}/2\left[\frac{a}{(\Delta\xi)^2}+\frac{c}{(\Delta\eta)^2}\right]
    \end{split}
  \end{align}
\end{document}
This makes it look like desired. See the final output in the attachment.
Attachments
olatex_101352.pdf
The output of the MWE.
(21.2 KiB) Downloaded 1599 times
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Alignment problem with split

Post by phi »

The LHS should be inside the split environment:

Code: Select all

  \begin{align}
    \begin{split}
      x_{i,j}=&\left\{\frac{a}{(\Delta\xi)^2}\left(x_{i+1,j}+x_{i-1,j}\right)+\frac{c}{(\Delta\eta)^2}\left(x_{i,j+1}+x_{i,j-1}\right){} \right.\\
      &\left.-\frac{b}{2\Delta\xi\Delta\eta}\left(x_{i+1,j+1}-x_{i+1,j-1}-x_{i-1,j+1}+x_{i-1,j-1}\right)\right\}/2\left[\frac{a}{(\Delta\xi)^2}+\frac{c}{(\Delta\eta)^2}\right]
    \end{split}
  \end{align}
And if you have a single equation with multiple lines, you should use an equation environment rather than an align environment.
Post Reply