1

I am trying to write an equation using this LaTeX code

\begin{equation}
\frac{n_d}{m_d}.\psi\left(x+1,y\right)+\frac{n_d}{m_d}.\psi\left(x-1,y\right)-2.\left(\frac{n_d}{m_d}+\frac{m_d}{n_d}\right).\psi\left(x,y\right)+\frac{m_d}{n_d}.\psi\left(x,y+1\right)+\frac{m_d}{n_d}.\psi\left(x,y-1\right)=m_d*n_d*\frac{q}{\epsilon}\left(n-p-C\right)
\end{equation}

but when I compile it I can only see a part of the equation in the generated pdf.

user80147
  • 11
  • 1

3 Answers3

1

Your equation is too long to fit in one line. You could use the split environment, with the amsmath package, to break it in two or more lines:

\documentclass[10pt]{article}

\usepackage{amsmath}
\begin{document}

\begin{equation}
\begin{split}
\frac{n_d}{m_d}\cdot\psi\left(x+1,y\right)+\frac{n_d}{m_d}\cdot\psi\left(x-1,y\right)-2\cdot\left(\frac{n_d}{m_d}+\frac{m_d}{n_d}\right)\cdot\psi\left(x,y\right) \\
+\frac{m_d}{n_d}\cdot\psi\left(x,y+1\right)+\frac{m_d}{n_d}\cdot\psi\left(x,y-1\right)=m_dn_d\frac{q}{\epsilon}\left(n-p-C\right)
\end{split}
\end{equation}

\end{document}
MarcoG
  • 1,437
1

If an equation is too long to fit on a single line, you need to employ an alternative environment that allows for line breaks. The multline environment (provided by the amsmath package) would seem to be well suited for your equation.

I would also replace all instances of . and * (dots and stars) with simple thinspaces.

enter image description here

\documentclass{article}
\usepackage{amsmath} % for "multline"  environment

\begin{document}

\noindent
before: \texttt{equation} environment
\begin{equation}
\frac{n_d}{m_d}.\psi\left(x+1,y\right)+\frac{n_d}{m_d}. \psi\left(x-1,y\right)-2. \left(\frac{n_d}{m_d}+\frac{m_d}{n_d}\right). \psi\left(x,y\right)+\frac{m_d}{n_d}. \psi\left(x,y+1\right)+\frac{m_d}{n_d}. \psi\left(x,y-1\right)=m_d*n_d*\frac{q}{\epsilon}\left(n-p-C\right)
\end{equation}

\bigskip\noindent
after: \texttt{multline} environment, no ``.'' or ``$*$'', no \verb+\left+ or \verb+\right+ directives
\begin{multline}
\frac{n_d}{m_d}\, \psi(x+1,y)+\frac{n_d}{m_d}\, \psi(x-1,y)
-2\, \Bigl(\frac{n_d}{m_d}+\frac{m_d}{n_d}\Bigr)\, \psi(x,y)\\
+\frac{m_d}{n_d}\, \psi(x,y+1)+\frac{m_d}{n_d}\, \psi(x,y-1)
=m_d\, n_d\, \frac{q}{\epsilon}(n-p-C)
\end{multline}

\end{document} 
Mico
  • 506,678
1

Here are two solutions. I used the geometry package, to have more sensible margins, and a split environment. In the second suggestion, I grouped terms in the l.h.s. In both I removed the useless dots, and all \left … \right pairs, replacing only the middle one with a pait \biggl … \biggr (the smaller size \Bigl … \Bigr might be OK too):

\documentclass{article}

\usepackage{mathtools} \usepackage[showframe]{geometry} \begin{document}

\begin{equation} \begin{split} \frac{n_d}{m_d} \psi(x+1,y) & +\frac{n_d}{m_d}.\psi(x-1,y)-2 \biggl(\frac{n_d}{m_d}+ \frac{m_d}{n_d}\biggr) \psi(x,yt) + \frac{m_d}{n_d}\psi(x,y+1)+\frac{m_d}{n_d}\psi(x,y-1) \ & =m_dn_d\frac{q}{\epsilon}(n-p-C) \end{split} \end{equation}

\begin{equation} \begin{split} \frac{n_d}{m_d}\bigl((\psi(x+1,y) + \psi(x-1,y)\bigr) & -2 \biggl(\frac{n_d}{m_d}+ \frac{m_d}{n_d}\biggr) \psi(x,yt) + \frac{m_d}{n_d}\bigl(\psi(x,y+1)+\psi(x,y-1)\bigr) \ & =m_dn_d\frac{q}{\epsilon}(n-p-C) \end{split} \end{equation}

\end{document}

enter image description here

Bernard
  • 271,350