4

I am trying to write this code. It is compiled without an error, but I want to reduce the distance between plus/minus sign and \sum sign. How can I do that? Can anyone help me?

\begin{gather}
\begin{split}
&-\sum_{\forall l\in\phi^L\mid SB(l)=n} P_l^k
+\sum_{\forall l\in\phi^L\mid RB(l)=n} P_l^k
+\sum_{\forall g\in\phi^{G-n}} P_{ng}^k +R_n^k\\
=&\bar{P}_{nd}
+\hat P_{nd}\cdot u_n^{+k}
-\hat P_{nd}\cdot u_n^{-k}~~
\forall n\in\phi^N,\forall k\in\phi^{iteration}\\
\end{split}
\end{gather}
Mico
  • 506,678
mostafa
  • 137

2 Answers2

4

I suggest you do the following:

  • Load the mathtools package (this package is a superset of the well-known amsmath package

  • Delete all \forall macros

  • Replace the \mid in the first two subscripts with s.t. ("such that") and use the \substack macro to introduce a line break in the first two subscript expression

  • Use the macro \smashoperator to let the subscript material protrude to the left and right of the summation symbols without increasing a lot of extra white space -- this addresses the request you posted in your query

  • Place the explanatory terms \forall n\in\phi^N,\forall k\in\phi^{iteration} on a line below the displayed math part

  • write \textit{SB}, \textit{RB}, and \textrm{iteration} to recognize that the groups of letters involved don't represents products of single-letter variables

  • Optional: since the letter "l" ("ell", not the numeral 1) occurs frequently, I'd use \ell rather than just l to write it out.

With these adjustments in place, it's possible to have all the math material take up a single that can be typeset using a "plain" equation environment.

enter image description here

\documentclass{article}
\usepackage{mathtools}
\newcommand\st{\textrm{ s.t.}}
\begin{document}
\begin{equation}
-\smashoperator{\sum_{\substack{\ell\in\phi^\ell\st \\ \textit{SB}(\ell)=n}}} P_\ell^k
+\smashoperator{\sum_{\substack{\ell\in\phi^\ell\st\\ \textit{RB}(\ell)=n}}} P_\ell^k
+\smashoperator{\sum_{ g\in\phi^{G-n}}} P_{ng}^k +R_n^k\\
=\bar{P}_{nd}
+\widehat P_{nd}\cdot u_n^{+k}
-\widehat P_{nd}\cdot u_n^{-k}
\end{equation}
for all $n\in\phi^N$ and $k\in\phi^{\textup{iteration}}$.
\end{document}
Mico
  • 506,678
  • In my project there is letter like n,d,g and k which occurs currently. What can i use for these letters like \ell instead of l? – mostafa Oct 13 '14 at 20:14
  • @mostafa - I'm afraid I don't fully understand your question. I had suggested using \ell instead of l to avoid potential confusion over whether the symbol might mean 1 ("one"). To the best of my knowledge, there's no risk of confusing the letters n, d, g, and k with any other symbols, right? – Mico Oct 13 '14 at 20:29
  • @Mico- You are right. I though that there is alternative format for typing these letters n,d,g and k. like \ell for l or \kappa for k. – mostafa Oct 13 '14 at 20:33
2

Here is a way to do things. You should  have mathtools installed; it's an extension of amsmath that is quite useful for fine-tuning equations layout. I use mathclap{ … }, but you can replace it with the much more verbose \makebox[0pt]{$ … $}. I also define a \widebar command (taken in the mathx font, from mathabx (which I do not load, as it redefines most mathematical symbols), and redefine \widehat, which looks better with capital letters than \hat. Finally, I replace the split environment with the multi-alignment points environment alignedat.

 \documentclass[a4paper, 11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{geometry}

\usepackage{mathtools}
\DeclareFontFamily{U}{mathx}{\hyphenchar\font45}
\DeclareFontShape{U}{mathx}{m}{n}{ <-> mathx10}{}
\DeclareSymbolFont{mathx}{U}{mathx}{m}{n}
\DeclareFontSubstitution{U}{mathx}{m}{n}
\DeclareMathAccent{\widebar}{0}{mathx}{"73}
\DeclareMathAccent{\widehat}{0}{mathx}{"70}

\begin{document}

\begin{equation}
\begin{alignedat}{2}
\MoveEqLeft[8]\enspace ∑_{\substack{l ∈ ϕ^L\\ \mathclap{SB(l)=n}}} P_l^k
+∑_{\substack{ l ∈ ϕ^L\\\mathclap{RB(l)=n}}} P_l^k
  +∑_{\mathclap{g ∈ ϕ^{G-n}}} P_{ng}^k +R_n^k\\%[-1.5ex]
 & = \widebar{P}_{nd}
+\widehat P_{nd} · u_n^{+k}
-\widehat P_{nd} · u_n^{-k}
 &\hspace{3em} & ∀ n ∈ ϕ^N,∀ k ∈ ϕ^{\text{iteration}}
\end{alignedat}
\end{equation}

\end{document} 

enter image description here

Bernard
  • 271,350