2

I need to stagger a system of difference equations so that incremented indices on proceeding lines appear underneath their corresponding index on the line above them. This has proven challenging because the indexed terms appear in a sequence of characters, which causes LaTeX to split elements that should be one term when & or && is applied between them.

Shown below are the first three equations, easily aligned at the equals sign. However, I also want to align functions 'u' whose indices match, i.e., 'u_{1,j}', 'u_{2,j}', etc., on the RHS.

Typing '\nonumber' is also a pain, makes no sense that this environment doesn't use * to suspend numbering. Is '{alignat*}{n} identical to '{align}' in every other sense? does 'n' stand for the number of equations or the number of alignment points? (please ignore this paragraph if '{alignat*}' isn't the solution to my problem anyway.

Also,

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[]{amsthm} 
\usepackage[]{amssymb} 
\usepackage[]{amsmath}
\usepackage{textcomp}
\usepackage{chngcntr}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{wrapfig}
\usepackage{physics}


\usepackage{listings}
\usepackage{xcolor}
\usepackage[T1]{fontenc}
\usepackage[numbered]{matlab-prettifier}


\lstset{frame=tb,
  language=Java,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  tabsize=3

\begin{align}
\boldsymbol{u_{1,j+1}} &= 0 + \left(1-2\boldsymbol{r}\right)\boldsymbol{u_{1,j}} + \boldsymbol{r u_{2,j}}\nonumber\\
\boldsymbol{u_{2,j+1}} &= \boldsymbol{r}\boldsymbol{u_{1,j}} + \left(1-2\boldsymbol{r}\right)\boldsymbol{u_{2,j}} + \boldsymbol{r u_{3,j}}\nonumber\\
\boldsymbol{u_{3,j+1}} &= \boldsymbol{r}\boldsymbol{u_{2,j}} + \left(1-2\boldsymbol{r}\right)\boldsymbol{u_{3,j}} + \boldsymbol{r u_{4,j}}\nonumber\\
\nonumber\end{align}

Result should look similar to

enter image description here

All help is appreciated. Thank you

2

enter image description here

with alignat*; instead of amsmath i use mathtools (for \shortintertext) and for bold face math font i suggest to use package \bm:

\documentclass{article}
\usepackage{mathtools}
\usepackage{bm}

\begin{document}
    \begin{alignat*}{5}
\bm{u}_{1,j+1}
    & = 0 + (1-2 & \bm{r}) & \bm{u}_{1,j} + \bm{r u}_{2,j} &&    \\
\bm{u}_{2,j+1}
    & =          & \bm{r}~ & \bm{u}_{1,j} + (1-2
                        & \bm{r})& \bm{u}_{2,j} + \bm{r u}_{3,j}
\shortintertext{\hspace{8em}\dotfill\hspace*{3.5em}}
\bm{u}_{3,j+1}
    & = &  &            & \bm{r}~ & \bm{u}_{2,j} + (1-2\bm{r})\bm{u}_{3,j} + \bm{r u}_{4,j}
    \end{alignat*}
\end{document}
  • interesting, except that the dots are "running away". you might want to put a matching \hspace (plus something for a "stopper", either \kern0pt or a strut) at the ribht-hand end of the intertext. – barbara beeton Mar 5 '18 at 16:10
  • @barbarabeeton, done. very rudimentary :-) – Zarko Mar 5 '18 at 17:27
2

It is easy with alignat* (note the starred version ads no number). This makes $5$ alignment points, hence it requires 9 ampersands. I removed all unnecessary packages for the problem at hand, and moved the language option of babel to the document cleass, as should be since version 3.10:

\documentclass[english]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{amsfonts, amssymb, amsmath}

\begin{document}

\begin{alignat*}{5}
\boldsymbol{u_{1,j+1}} &={}&0 +(1-2\boldsymbol{r})\boldsymbol{u_{1,j}} & &{}+ \boldsymbol{r u_{2,j}} &\\
\boldsymbol{u_{2,j+1}} &= & \boldsymbol{r}\boldsymbol{u_{1,j}} & &{} + (1-2\boldsymbol{r})\boldsymbol{u_{2,j}} & &{}+ \boldsymbol{r u_{3,j}} & \\
\boldsymbol{u_{3,j+1}} &= & & & \boldsymbol{r}\boldsymbol{u_{2,j}} & &{}+(1-2\boldsymbol{r})\boldsymbol{u_{3,j}} & & {}+ \boldsymbol{r u_{4,j}} &
\end{alignat*}

\end{document} 

enter image description here

1

A vertically spaced out array should suffice:

\documentclass{article}
\usepackage{amsmath,array}

\begin{document}

\begin{equation*}
\renewcommand{\arraystretch}{1.5}
\setlength{\arraycolsep}{0pt}
\begin{array}{r >{{}}c<{{}} r<{{}} >{{}}c<{{}} r >{{}}c<{{}} ll}
u_{1,j+1}   & = & 0+(1-2r)u_{1,j} & + & ru_{2,j} \\
u_{2,j+1}   & = &        ru_{1,j} & + & (1-2r)u_{2,j} & + & ru_{3,j} \\
& \multicolumn{7}{c}{\;\dotfill\hphantom{{}+0}} \\
u_{N-1,j+1} & = & &&&&& ru_{N-2,j}+(1-2r)u_{N-1,j}+0
\end{array}
\end{equation*}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.