1

My code is

\newcommand\rsx[1]{\left.{#1}\vphantom{\Big|}\right|}
\begin{eqnarray}
&&let \;\; L(\bf{X},\lambda,\mu)= f(\bf{X})+\sum_{i=1}^p \lambda_{i}h_{i}(\bf{X})+\sum_{j=1}^q\mu_{j}g_{j}(\bf{X}) \nonumber\\
&& \;\;\;\;\; \rsx{\frac{\partial L}{\partial \bf{X}}}_{\bf{X}=\bf{X^*}}=0 \nonumber\\
&& \;\;\;\;\; \lambda_{i}\neq0,\;\;\;\mu_{j}\geq0,\;\;\;\nonumber\\
&& \;\;\;\;\; \mu_{j}g_{j}(\bf{X^*})=0,\;\;\; h_{i}(\bf{X}^*)=0 \;\;\; g_{j}(\bf{X^*})\leq0
\label{equ: KKT conditions}
\end{eqnarray}

and below is the result, as can be seen in this figure, the font type is different in these equations, why (see the letter "g" in different lines)?

See the letter "g" in different lines

  • 1
    You should use \mathbf instead of \bf I think... try it and see if it helps! Welcome to TeX.SX! Also, you may want to consider avoiding eqnarray: http://tex.stackexchange.com/a/197/32374 – darthbith Nov 28 '14 at 03:23
  • @darthbith Thanks for your answer, I have solved this problem by adding \usepackage{bm} and replacing \bf with \bm, becaues we can not use \bf{x} to keep other letters from boldface. And thanks for your reminder of avoiding eqnarray. I'm trying other commands. – SongAn Zhang Nov 28 '14 at 03:50
  • Glad it helped! You can write that as an answer to your own question and then people will see that it is solved :-) – darthbith Nov 28 '14 at 03:56
  • 1
    The problem with \bf is just that you used the incorrect syntax but bm uses a different type of bold altogether. \bf uses bold upright roman, which should be accessed by \mathbf{x} whereas \bm{x} gives bold math italic. – David Carlisle Nov 28 '14 at 09:20

2 Answers2

2

The alignment points could get some nicer fine-tuning, but I just wanted to correct some issues in your code. This is how I would type your formula:

% arara: pdflatex

\documentclass{article}
\usepackage{mathtools}
\newcommand{\pder}[2][]{\frac{\partial#1}{\partial#2}}
\newcommand\numberthis{\addtocounter{equation}{1}\tag{\theequation}}

\begin{document}
\begin{align*}
\MoveEqLeft[7]\text{let } L(\mathbf{X},\lambda,\mu)= f(\mathbf{X})+\sum_{i=1}^p \lambda_{i}h_{i}(\mathbf{X})+\sum_{j=1}^q\mu_{j}g_{j}(\mathbf{X})\\
    \pder[L]{\mathbf{X}}\biggr|_{\mathbf{X}=\mathbf{X}^*}&=0\\
    \lambda_{i}&\neq 0,\quad\mu_{j}\geq 0,\\
    \mu_{j}g_{j}(\mathbf{X}^*)&=0,\quad h_{i}(\mathbf{X}^*)=0,\quad g_{j}(\mathbf{X}^*)\leq 0 \numberthis\label{equ:KKTconditions}
\end{align*}
\end{document}

enter image description here


or:

\begin{align*}
\MoveEqLeft[2]\text{let } L(\mathbf{X},\lambda,\mu)= f(\mathbf{X})+\sum_{i=1}^p \lambda_{i}h_{i}(\mathbf{X})+\sum_{j=1}^q\mu_{j}g_{j}(\mathbf{X})\\
    &\pder[L]{\mathbf{X}}\biggr|_{\mathrlap{\mathbf{X}=\mathbf{X}^*}}=0\\
    &\lambda_{i}\neq 0,\quad\mu_{j}\geq 0,\\
    &\mu_{j}g_{j}(\mathbf{X}^*)=0,\quad h_{i}(\mathbf{X}^*)=0,\quad g_{j}(\mathbf{X}^*)\leq 0 \numberthis\label{equ:KKTconditions}
\end{align*}

enter image description here

LaRiFaRi
  • 43,807
2

The command \bf is a Plain-TeX command. While it continues to work in LaTeX, it's considered deprecated for use in LaTeX.

The immediate cause of the problem you've encountered is an incorrect use of \bf: it is a switch and doesn't take an argument. Hence, you should write {\bf ...} instead of \bf{...}. As you've "discovered", the scope of \bf{...} ... is not the material inside the curly braces; it extends to the end of the current (math) group.

For a LaTeX document, one shouldn't use \bf anymore. Write \textbf{...} or {\bfseries ...} for text material. For math material, use \mathbf{...} if you want upright bold letters and \bm{...} (which requires the bm package) if you want italic bold letters.

There are two additional issues with your code snippet:

  • Don't use the eqnarray environment: it's badly deprecated. Use an environment such as align instead. See the posting eqnarray vs align for a thorough examination of the reasons for not using eqnarray.

  • You seem to be engaging in quite a bit of visual formatting. This makes the code both hard to read and less flexible than you would probably like it to be. The code below suggests some alternative measures, and uses align instead of eqnarray. It also shows the different effects generated by \mathbf and \bm.

enter image description here

\documentclass{article}
\usepackage{amsmath}  % for 'align' environment
\usepackage{bm}
\newcommand\rsx[1]{#1\vphantom{\Big|}\bigg\rvert}

\begin{document}

First with \verb+\bm{...}+:
\begin{align}
\text{Let }&L(\bm{X},\lambda,\mu)= f(\bm{X})
  +\sum_{i=1}^p \lambda_{i}h_{i}(\bm{X})
  +\sum_{j=1}^q\mu_{j}g_{j}(\bm{X}) \nonumber\\
&\rsx{\frac{\partial L}{\partial\bm{X}}}
  _{\bm{X}=\bm{X^*}} =0 \nonumber\\
&\lambda_{i}\neq0,\quad \mu_{j}\geq0,\nonumber\\
&\mu_{j} g_{j}(\bm{X^*})=0,\quad 
  h_{i}(\bm{X}^*)=0,\quad 
  g_{j}(\bm{X^*})\leq0
\label{equ:KKT_conditions}
\end{align}

\bigskip
Second with \verb+\mathbf{...}+
\begin{align}
\text{Let }&L(\mathbf{X},\lambda,\mu)= f(\mathbf{X})
  +\sum_{i=1}^p \lambda_{i}h_{i}(\mathbf{X})
  +\sum_{j=1}^q\mu_{j}g_{j}(\mathbf{X}) \nonumber\\
&\rsx{\frac{\partial L}{\partial\mathbf{X}}}
  _{\mathbf{X}=\mathbf{X^*}} =0 \nonumber\\
&\lambda_{i}\neq0,\quad \mu_{j}\geq0,\nonumber\\
&\mu_{j} g_{j}(\mathbf{X^*})=0,\quad 
  h_{i}(\mathbf{X}^*)=0,\quad 
  g_{j}(\mathbf{X^*})\leq0
\label{equ:KKT_conditions_alt}
\end{align}

\end{document} 
Mico
  • 506,678