0

I'm trying to write an equation using display math mode but I'm facing some problems :

  1. the equations aren't centered
  2. the equations coming in one line even when I separate them using (double)\\
    \begin{equation}
    G_t = R_{t+1} + \gamma R_{t+2} +\gamma^2 R_{t+3} + \gamma^3 R_{t+4}+\dots \\

    G_t = R{t+1} + \gamma( R_{t+2} +\gamma R_{t+3} + \gamma^2 R_{t+4}+\dots) \\
 
    G_t = R_{t+1} + \gamma G_{t+1}\\

    \end{equation}
2
  • 3
    The equation environment is for single equations. \\ doesn't generate a line break within the equation environment. Perhaps you need something like the align environment. Jan 14 at 15:35
  • thanks for your advice
    – Karam
    Jan 14 at 15:36
1

As @IanThompson said in the comments, the equation environment is made for equations spanning a single line. There are other environments, such as align, alignat and gather, which should be used when multiple lines of equations are to be displayed. If you want the equations to be centered, you can use gather like in the following example.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{gather}
G_t = R_{t+1} + \gamma R_{t+2} +\gamma^2 R_{t+3} + \gamma^3 R_{t+4}+\dots \\
G_t = R{t+1} + \gamma( R_{t+2} +\gamma R_{t+3} + \gamma^2 R_{t+4}+\dots) \\
G_t = R_{t+1} + \gamma G_{t+1}
\end{gather}

\end{document}

However, here it might be more appropriate not to center every equation, but rather to center the block as a whole, and to align the equal signs. For this the align environment can be used as in the following example.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{align}
G_t & = R_{t+1} + \gamma R_{t+2} +\gamma^2 R_{t+3} + \gamma^3 R_{t+4}+\dots \\
    & = R{t+1} + \gamma( R_{t+2} +\gamma R_{t+3} + \gamma^2 R_{t+4}+\dots) \\
    & = R_{t+1} + \gamma G_{t+1}
\end{align}

\end{document}

Note also that display math environments do not accept blank lines, which is why I removed them from your example.

2
  • This looks like simplification on successive lines. I would use align with G_t on the first line only. Jan 14 at 15:45
  • @IanThompson I would do the same, but I used gather since the OP specified that one of the problems was that the equations were not centered. But this is indeed ambiguous; I will add another solution with align.
    – Vincent
    Jan 14 at 15:48

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.