3

Hey I have following code and I would like to set last equality into box but when I use \boxed I have an error. What can I do?

\begin{eqnarray*}
    \Theta _{C} &=&\frac{\partial }{\partial t}\left( C\right) =qSe^{-q\left(
        T-t\right) }N\left( d_{+}\right) -rKe^{-r\left( T-t\right) }N\left(
    d_{-}\right)  \\
    &&+Se^{-q\left( T-t\right) }n\left( d_{+}\right) \sigma \frac{-1}{2\sqrt{T-t}%
    } \\
    &=&qSe^{-q\left( T-t\right) }N\left( d_{+}\right) -rKe^{-r\left( T-t\right)
    }N\left( d_{-}\right)\\
    &&-Se^{-q\left( T-t\right) }n\left( d_{+}\right) \frac{%
        \sigma }{2\sqrt{T-t}} \\
\end{eqnarray*}
8

Never use eqnarray under any circumstances; amsmath provides several environments for alignments that are more powerful and feature much better spacing.

Here you can use aligned nested inside align*.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{align*}
\Theta _{C}
   = \frac{\partial}{\partial t}(C)
  &= \begin{aligned}[t]
     &  qSe^{-q(T-t) }N( d_{+}) -rKe^{-r( T-t) } N(d_{-})  \\
     &+ Se^{-q( T-t) }n( d_{+}) \sigma \frac{-1}{2\sqrt{T-t}}
     \end{aligned}
\\[2ex]
  &= \boxed{\begin{aligned}[t]
     & qSe^{-q( T-t) }N( d_{+}) -rKe^{-r( T-t)}N( d_{-})\\
     &-Se^{-q( T-t) }n( d_{+}) \frac{\sigma }{2\sqrt{T-t}}
     \end{aligned}}
\end{align*}

\end{document}

An aligned environment can easily be \boxed.

enter image description here

Note that I removed all \left and \right commands that did nothing useful (and damaged the spacing).

Also, I moved the alignment point to the second “=” in the first line, for better symmetry.

3
  • 2
    Thanks it works! :)
    – HSmile
    Nov 5 '20 at 22:29
  • alignat -> aligned Nov 6 '20 at 13:02
  • 1
    @IanThompson Thanks, fixed
    – egreg
    Nov 6 '20 at 13:05
4

First, forget about eqnarray/eqnarray*. Use align/align* instead: https://www.texfaq.org/FAQ-eqnarray.

\documentclass[12pt]{article}
\usepackage{amsmath,amssymb}


\begin{document}
\begin{align*}
    \Theta_{C}&=\frac{\partial }{\partial t}\left( C\right)=qSe^{-q\left(
        T-t\right) }N\left( d_{+}\right) -rKe^{-r\left( T-t\right) }N\left(
    d_{-}\right)  \\
    &+Se^{-q\left( T-t\right) }n\left( d_{+}\right) \sigma \frac{-1}{2\sqrt{T-t}%
    } \\
    &=qSe^{-q\left( T-t\right) }N\left( d_{+}\right) -rKe^{-r\left( T-t\right)
    }N\left( d_{-}\right)\\
    &-Se^{-q\left( T-t\right) }n\left( d_{+}\right) \frac{%
        \sigma }{2\sqrt{T-t}} \\
\end{align*}
\end{document}

enter image description here

Here there is the boxed formula using empheq package.

\documentclass[12pt]{article}
\usepackage{amsmath,amssymb}
\usepackage{empheq}
\begin{document}
\begin{empheq}[box=\fbox]{align*}
    \Theta_{C}&=\frac{\partial }{\partial t}\left( C\right)=qSe^{-q\left(
        T-t\right) }N\left( d_{+}\right) -rKe^{-r\left( T-t\right) }N\left(
    d_{-}\right)  \\
    &+Se^{-q\left( T-t\right) }n\left( d_{+}\right) \sigma \frac{-1}{2\sqrt{T-t}%
    } \\
    &=qSe^{-q\left( T-t\right) }N\left( d_{+}\right) -rKe^{-r\left( T-t\right)
    }N\left( d_{-}\right)\\
    &-Se^{-q\left( T-t\right) }n\left( d_{+}\right) \frac{%
        \sigma }{2\sqrt{T-t}}
\end{empheq}
\end{document}

enter image description here

Addendum 1: "to set into box only last equation, i.e only last two lines, without "=" sign" (see the comment).

\documentclass[12pt]{article}
\usepackage{amsmath,amssymb}
\usepackage{empheq}
\begin{document}
\begin{align*}
    \Theta_{C}&=\frac{\partial }{\partial t}\left( C\right)=qSe^{-q\left(
        T-t\right) }N\left( d_{+}\right) -rKe^{-r\left( T-t\right) }N\left(
    d_{-}\right)  \\
    &+Se^{-q\left( T-t\right) }n\left( d_{+}\right) \sigma \frac{-1}{2\sqrt{T-t}%
    } 
    \end{align*}
\begin{empheq}[innerbox=\fbox]{align*}
   qSe^{-q\left( T-t\right) }N\left( d_{+}\right) -rKe^{-r\left( T-t\right)
    }N\left( d_{-}\right) &\\
    -Se^{-q\left( T-t\right) }n\left( d_{+}\right) \frac{%
        \sigma }{2\sqrt{T-t}} &
\end{empheq}
\end{document}

enter image description here

Addendum 2: From the comment of @Barbarabeeton "Where is the equal sign for the boxed material in the last version".

\documentclass[12pt]{article}
\usepackage{amsmath,amssymb}
\usepackage{empheq}
\begin{document}
\begin{align*}
    \Theta_{C}&=\frac{\partial}{\partial t}(C)=qSe^{-q(
        T-t)}N(d_{+})-rKe^{-r(T-t}N(
    d_{-})  \\
    &+Se^{-q(T-t)}n(d_{+}) \sigma\frac{-1}{2\sqrt{T-t}%
    } 
    \end{align*}
\begin{empheq}[box=\fbox]{align*}
\MoveEqLeft
   =qSe^{-q(T-t)}N(d_{+})-rKe^{-r(T-t)
    }N(d_{-}) \\
   &-Se^{-q(T-t)}n(d_{+}) \frac{%
        \sigma}{2\sqrt{T-t}} 
\end{empheq}

\end{document}

enter image description here

13
  • 1
    I suggest you recommend not using eqnarray with the following reference: texfaq.org/FAQ-eqnarray
    – ivankokan
    Nov 5 '20 at 21:57
  • 1
    @ivankokan Yes, in the meantime I'm putting the boxed formula. However you can edit my question adding your link if you prefer. Welcome :-)
    – Sebastiano
    Nov 5 '20 at 21:59
  • 1
    @HSmile Work in progress :-)
    – Sebastiano
    Nov 5 '20 at 22:03
  • 2
    Thanks but it still doesnt solve my problem. You set all equations into box, but I would like to set into box only last equation, i.e only last two lines, without "=" sign (sign "-" easy to move to the right by \quad command but how to put this into box?)
    – HSmile
    Nov 5 '20 at 22:12
  • 1
    @HSmile Can you see if now is better? Thanks.
    – Sebastiano
    Nov 5 '20 at 22:28

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.