6

I have tried for over one hour now, in vain, on centering one equation. Why in the world is the equation not centered - i.e., so much margin on the left??

Here is my code:

\documentclass[10pt]{article}
\begin{document}
$$\frac{dX_{SS}}{dt}=\Lambda-\mu X_{SS}-\frac{\beta\bigg(X_{HS}+X_{HT}+X_{H+{T_T^{(1)}}}+X_{H+T_T^{(2)}}
+X_{H+T_T^{(3)}}\bigg)}{N}-\frac{\tau(X_{ST}+X_{HT})X_{SS}}{N}$$
\end{document}

And the output:

enter image description here

I have tried flalign, raggedleft, raggedright, with amsmath package, etc...

  • Please, don't use $$...$$ for one-line displayed maths in LaTeX documents; use \[...\] instead (See http://tex.stackexchange.com/questions/503/why-is-preferable-to). – Gonzalo Medina Jul 17 '14 at 03:30

3 Answers3

5

You have several ways: I'll present four. In all, the long fraction line has been replaced by \frac{1}{N} in front of the numerator, which is probably less heavy to read. The examplese after the first actually have \tfrac{1}{N} which is possibly even better. Exercise your taste.

\documentclass[10pt]{article}
\usepackage{amsmath}
\begin{document}

I have tried for over one hour now, in vain, on centering one equation. Why in the world is 
the equation not centered---i.e., so much margin on the left?
\begin{equation*}
\begin{split}
\frac{dX_{SS}}{dt}=\Lambda-\mu X_{SS}
  &-\frac{1}{N}
      \beta\bigl(X_{HS}+X_{HT}+X_{H+T_T^{(1)}}+X_{H+T_T^{(2)}}+X_{H+T_T^{(3)}}\bigr)\\
  &-\frac{1}{N}\tau(X_{ST}+X_{HT})X_{SS}
\end{split}
\end{equation*}
I have tried for over one hour now, in vain, on centering one equation. Why in the world is 
the equation not centered---i.e., so much margin on the left?
\begin{equation*}
\begin{split}
\frac{dX_{SS}}{dt}=\Lambda-\mu X_{SS}
  &-\tfrac{1}{N}
      \beta\bigl(X_{HS}+X_{HT}+X_{H+T_T^{(1)}}+X_{H+T_T^{(2)}}+X_{H+T_T^{(3)}}\bigr)\\
  &-\tfrac{1}{N}\tau(X_{ST}+X_{HT})X_{SS}
\end{split}
\end{equation*}
I have tried for over one hour now, in vain, on centering one equation. Why in the world is 
the equation not centered---i.e., so much margin on the left?
\begin{multline*}
\frac{dX_{SS}}{dt}=\Lambda-\mu X_{SS}
  -\tfrac{1}{N}
      \beta\bigl(X_{HS}+X_{HT}+X_{H+T_T^{(1)}}+X_{H+T_T^{(2)}}+X_{H+T_T^{(3)}}\bigr)\\
  -\tfrac{1}{N}\tau(X_{ST}+X_{HT})X_{SS}
\end{multline*}
I have tried for over one hour now, in vain, on centering one equation. Why in the world is 
the equation not centered---i.e., so much margin on the left?
\begin{multline*}
\frac{dX_{SS}}{dt}=\Lambda-\mu X_{SS}\\
  -\tfrac{1}{N}
      \beta\bigl(X_{HS}+X_{HT}+X_{H+T_T^{(1)}}+X_{H+T_T^{(2)}}+X_{H+T_T^{(3)}}\bigr)\\
  -\tfrac{1}{N}\tau(X_{ST}+X_{HT})X_{SS}
\end{multline*}
I have tried for over one hour now, in vain, on centering one equation. Why in the world is 
the equation not centered---i.e., so much margin on the left?

\end{document}

enter image description here

egreg
  • 1,121,712
4

As you can see from the enlarged version, the equation is longer then \textwidth, hence cannot be centered. But, in general instead of TeX $$...$$, a LaTeX \[...\] (or other structure) should be used. See Why is \[ ... \] preferable to $$ ... $$?

\documentclass[10pt]{article}
\begin{document}


I have tried for over one hour now, in vain, on centering one equation. Why in the world is the equation not centered - i.e., so much margin on the left??

$$\frac{dX_{SS}}{dt}=\Lambda-\mu X_{SS}-\frac{\beta\bigg(X_{HS}+X_{HT}+X_{H+{T_T^{(1)}}}+X_{H+T_T^{(2)}}
+X_{H+T_T^{(3)}}\bigg)}{N}-\frac{\tau(X_{ST}+X_{HT})X_{SS}}{N}$$




I have tried for over one hour now, in vain, on centering one equation. Why in the world is the equation not centered - i.e., so much margin on the left??
\end{document}

enter image description here

But it is better to split too long equation:

\documentclass[10pt]{article}
\usepackage{amsmath}
\begin{document}


I have tried for over one hour now, in vain, on centering one equation. Why in the world is the equation not centered - i.e., so much margin on the left??

\begin{align*}
\frac{dX_{SS}}{dt}&=\Lambda-\mu X_{SS}-\frac{\beta\bigg(X_{HS}+X_{HT}+X_{H+{T_T^{(1)}}}+X_{H+T_T^{(2)}}
+X_{H+T_T^{(3)}}\bigg)}{N}\\
&\quad{}-\frac{\tau(X_{ST}+X_{HT})X_{SS}}{N}
\end{align*}




I have tried for over one hour now, in vain, on centering one equation. Why in the world is the equation not centered - i.e., so much margin on the left??


\end{document}

enter image description here

  • How can I make it look proper and "nice"? I tried reducing the fontsize to 4pt but it made no difference. –  Jul 17 '14 at 03:22
  • @Anonymous What about spliting on tle last - sign? – Przemysław Scherwentke Jul 17 '14 at 03:24
  • That's ok, but can I make the equations themselves smaller font? –  Jul 17 '14 at 03:25
  • 2
    @Anonymous You can say, e.g., {\footnotesize (your equation)}, but it is a last resort. Splitting into lines is a normal practice. – Przemysław Scherwentke Jul 17 '14 at 03:29
  • 1
    @PrzemysławScherwentke Could you please suggest in you answer not to use $$...$$ for one-line displayed maths in LaTeX documents, but to use \[...\] instead? (Even though I know the real problem here is not that, but in any case it's a useful advise, in my opinion). – Gonzalo Medina Jul 17 '14 at 03:36
  • @GonzaloMedina The proper suggestion is in the second version. I have left $$'s as immune to options acting onto LaTeX equation structures. – Przemysław Scherwentke Jul 17 '14 at 03:41
  • @PrzemyslawScherwentke Thank you! I presume if I take out the * in \begin{align*}, I will get numbered equation? I am getting two numbers instead of one. –  Jul 17 '14 at 03:42
  • @Anonymous Yes, but you can say \nonumber in a chosen line, or nest e.g. aligned in equation. See, e.g., http://tex.stackexchange.com/questions/111891/aligned-environment-of-amsmath-vs-array-environment – Przemysław Scherwentke Jul 17 '14 at 03:48
  • You can not force something impossible, if not fit ... split the equation with align* or multline. – skpblack Jul 17 '14 at 03:56
3

How about this solution that uses alignedat? There is only one number naturally:

    \documentclass[10pt]{article}
    \usepackage[utf8]{inputenc}
    \usepackage{lmodern}

    \usepackage{mathtools}

    \begin{document}

    I have tried for over one hour now, in vain, on centering one equation. Why in the world is the equation not centered - i.e., so much margin on the left??

    \begin{equation}
    \begin{alignedat}{2}
    \frac{dX_{SS}}{dt} &= \Lambda - \mu X_{SS} &  & -\frac{β \big(X_{HS}+X_{HT}+X_{H+{T_T^{(1)}}}+X_{H+T_T^{(2)}}+X_{H+T_T^{(3)}}\big)}{N} \\
     &  &  &  -\frac{τ(X_{ST}+X_{HT})X_{SS}}{N}
    \end{alignedat}
    \end{equation}

    \end{document} 

enter image description here

Bernard
  • 271,350