2

Normally I use the align tag and everything is aligned properly. But now for some reason the text isn't left aligned. The following is the code I normally use (code #1):

\begin{align*}
V[1] = A[1] & i = 1  \\
V[2] = \max \{ A[1], A[2] \} & i=2\\
V[i] = \max\{ V[i-1], V[i-2] + A[i] \} & i>2 
\end{align*}

By reading some Q&A I found a method in which the text is properly left aligned, but the spacing is too great (code #2):

\begin{align*}
V[1] &= A[1] &  i = 1  \\
V[2] &= \max \{ A[1], A[2] \} & i=2\\
V[i] &= \max\{ V[i-1], V[i-2] + A[i] \} & i>2 
\end{align*}

The following image shows the result of code#1 and code#2: enter image description here

How do I reduce the spacing in code#2 ?
(I don't have access to the tags above \begin{document} or below \end{document}, so please don't offer solutions which involve them)

0

1 Answer 1

1

Try with alignat:

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document} 

\begin{align*}
  V[1] &= A[1] &  i = 1 \\
  V[2] &= \max \{ A[1], A[2] \} & i=2 \\
  V[i] &= \max\{ V[i-1], V[i-2] + A[i] \} & i>2 
\end{align*}

\begin{alignat*}{2}
  V[1] &= A[1]                      & \quad i &= 1 \\
  V[2] &= \max \{ A[1], A[2] \}           & i &= 2 \\
  V[i] &= \max\{ V[i-1], V[i-2] + A[i] \} & i &> 2 
\end{alignat*}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .