4

When using:

\begin{center}equation\end{center}

The equation goes far to the right instead of being centred.

Example:

\documentclass{article}
\usepackage{cancel}
\usepackage[fleqn]{mathtools}
\usepackage[extreme]{savetrees}
\usepackage[version=4]{mhchem}
\usepackage{siunitx}
\thispagestyle{empty}
\setlength{\mathindent}{0pt}
\renewcommand{\familydefault}{\sfdefault}

\def\cd{\ \cdot\ }
\def\eq{\ =\ }
\def\pl{\ +\ }
\def\rarr{\ \Rightarrow\ }
\def\arr{\ \rightarrow}
\def\M{\unit{\ g \cd mol^{-1}}}
\def\pr#1{\begin{flushleft}#1\end{flushleft}}
\def\hed#1{\textbf{\pr{#1}}}


\usepackage{amsmath,amssymb}
\usepackage{mathastext}
\def\can#1{\cancel#1}

\def\gc{\ g \cd cm^{-3}}
\def\gm{\ g \cd mol^{-1}}
\def\cm3{\ cm^{3}\ }
\def\arr{\ \rightarrow\ }

\def\gc{\ g \cd cm^{-3}}
\def\gm{\ g \cd mol^{-1}}
\def\cm{\ cm^{3}\ }
\def\arr{\ \rightarrow\ }

\usepackage{parskip,amsmath}

% spacy math
%\thinmuskip=3mu
%\medmuskip=4mu plus 2mu minus 4mu
%\thickmuskip=5mu plus 5mu

\thinmuskip=5mu
\medmuskip=9mu plus 2mu minus 6mu 
\thickmuskip=12mu plus 5mu minus 5mu

\begin{document}

\hed{
  Moles, Molar Mass, Mass Equations:
}

$ 
  M[molar\ mass] \eq
    n[moles] 
    \cd
    m[mass]
    \\
    \\
$

$
  \displaystyle
  \frac{
    M
  }{
    n
  } 
  \eq
  \frac{
    n \cd m
  }{
    m
  }
  \rarr
  \frac{
    M
  }{
    n
  } 
  \eq
  \frac{
    n \cd \cancel{m}
  }{
    \cancel{m}
  }
  \rarr
  n \eq
  \frac{
    m
  }{
    M
  }
  \\
  \\
$

\begin{center}
\begin{large}
$
  \displaystyle
    n \eq
  \frac{
    M
  }{
    m
  }
$
\end{large}
\end{center}

\end{document}

enter image description here

Bad example of how I got what I wanted:

\documentclass{article}
\usepackage{cancel}
\usepackage[fleqn]{mathtools}
\usepackage[extreme]{savetrees}
\usepackage[version=4]{mhchem}
\usepackage{siunitx}
\thispagestyle{empty}
\setlength{\mathindent}{0pt}
\renewcommand{\familydefault}{\sfdefault}

\def\cd{\ \cdot\ }
\def\eq{\ =\ }
\def\pl{\ +\ }
\def\rarr{\ \Rightarrow\ }
\def\arr{\ \rightarrow}
\def\M{\unit{\ g \cd mol^{-1}}}
\def\pr#1{\begin{flushleft}#1\end{flushleft}}
\def\hed#1{\textbf{\pr{#1}}}


\usepackage{amsmath,amssymb}
\usepackage{mathastext}
\def\can#1{\cancel#1}

\def\gc{\ g \cd cm^{-3}}
\def\gm{\ g \cd mol^{-1}}
\def\cm3{\ cm^{3}\ }
\def\arr{\ \rightarrow\ }

\def\gc{\ g \cd cm^{-3}}
\def\gm{\ g \cd mol^{-1}}
\def\cm{\ cm^{3}\ }
\def\arr{\ \rightarrow\ }

\usepackage{parskip,amsmath}

% spacy math
%\thinmuskip=3mu
%\medmuskip=4mu plus 2mu minus 4mu
%\thickmuskip=5mu plus 5mu

\thinmuskip=5mu
\medmuskip=9mu plus 2mu minus 6mu 
\thickmuskip=12mu plus 5mu minus 5mu

\begin{document}

\hed{
  Moles, Molar Mass, Mass Equations:
}

$ 
  M[molar\ mass] \eq
    n[moles] 
    \cd
    m[mass]
    \\
    \\
$

$
  \displaystyle
  \frac{
    M
  }{
    n
  } 
  \eq
  \frac{
    n \cd m
  }{
    m
  }
  \rarr
  \frac{
    M
  }{
    n
  } 
  \eq
  \frac{
    n \cdot \cancel{m}
  }{
    \cancel{m}
  }
  \rarr
  n =
  \frac{
    m
  }{
    M
  }
  \\
  \\
$

\begin{large}
$
  \ \ \ \ \ \ \ \ 
   \ \ \ \ \ \ \ \
  \displaystyle
    n \eq
  \frac{
    M
  }{
    m
  }
  \\
$
\end{large}

\end{document}

enter image description here

Desired behaviour:

Have the last equation centred and maybe in bold

The equations are messed up, I'll fix them, but please ignore for now

Update using @DavidCarlisle's answer:

\documentclass{article}
\usepackage{cancel}
\usepackage[extreme]{savetrees}
\usepackage[version=4]{mhchem}
\usepackage{siunitx}
\thispagestyle{empty}
%\setlength{\mathindent}{0pt}
\renewcommand{\familydefault}{\sfdefault}

\def\cd{\ \cdot\ }
\def\eq{\ =\ }
\def\pl{\ +\ }
\def\rarr{\ \Rightarrow\ }
\def\arr{\ \rightarrow}
\def\M{\unit{\ g \cd mol^{-1}}}
\def\pr#1{\begin{flushleft}#1\end{flushleft}}
\def\hed#1{\textbf{\pr{#1}}}


\usepackage{amsmath,amssymb}
\usepackage{mathastext}

\def\gc{\ g \cd cm^{-3}}
\def\gm{\ g \cd mol^{-1}}
\def\cm3{\ cm^{3}\ }
\def\arr{\ \rightarrow\ }

\def\gc{\ g \cd cm^{-3}}
\def\gm{\ g \cd mol^{-1}}
\def\cm{\ cm^{3}\ }
\def\arr{\ \rightarrow\ }

\usepackage{parskip,amsmath}

% spacy math
%\thinmuskip=3mu
%\medmuskip=4mu plus 2mu minus 4mu
%\thickmuskip=5mu plus 5mu

\thinmuskip=5mu 
\medmuskip=29mu plus 2mu minus 12mu \thickmuskip=42mu plus 5mu minus 5mu

\begin{document}

\hed{
  Moles, Molar Mass, Mass Equations:
}

$ 
  M[molar\ mass] \eq
    n[moles] 
    \cd
    m[mass]
    \\
    \\
$

$
  \displaystyle
  \frac{
    M
  }{
    n
  } 
  \eq
  \frac{
    n \cdot m
  }{
    m
  }
  \rarr
  \frac{
    M
  }{
    n
  } 
  \eq
  \frac{
    n \cd \cancel{m}
  }{
    \cancel{m}
  }
  \rarr
  n \eq
  \frac{
    m
  }{
    M
  }
$

{\huge\boldmath
\[
    n \eq
  \frac{
    M
  }{
    m
  }
\]
}

\end{document}

enter image description here

Note the 2nd equation first is a \cdot (no spacing change from default), vs \cd (the second \cdot).

18
  • 1
    If you want a centred equation, why not use \[...\]? Aug 13, 2023 at 14:29
  • 1
    Please also note that large is not an environment. It works more or less by accident, but you should use {\large ...} Aug 13, 2023 at 14:29
  • 2
    I would start by removing all these definitions, it's simply wrong to use center for equations , or to ever use \ \ \ anywhere. It would be better to post an example with usable markup and describe how you want the output to change. Aug 13, 2023 at 15:10
  • 1
    of course \[ gives you flush left equations as you have specified that non-default option. \usepackage[fleqn]{mathtools} fleqn== flush left equations Aug 13, 2023 at 15:21
  • 1
    well, I went through your last question cleaning out \cd and \ this question is essentially a duplicate, the answer there covers this. Aug 13, 2023 at 15:23

2 Answers 2

4

To address your original problems:

  • The second equation is actually centered, with respect to the page. As the page is much wider than the first line of math, the second line seems to come out flush right. So you have to tell LaTeX to center the second line w.r.t. to the first one.
  • The second line is not bold, because there is no bold version of the font chosen.

In the following solution, I did two additional changes:

  • slanted font for math variables
  • corrected math reasoning in the first line

enter image description here

\documentclass{article}

% Use sf for text and math
\renewcommand{\familydefault}{\sfdefault}
\usepackage[helvet]{sfmath}% helvet has a bold slanted font

\usepackage{parskip}

\usepackage{mathtools}% also loads amsmath
\usepackage{cancel}

\def\pr#1{\begin{flushleft}#1\end{flushleft}}
\def\hed#1{\textbf{\pr{#1}}}

\thinmuskip=5mu
\medmuskip=9mu plus 2mu minus 6mu 
\thickmuskip=12mu plus 5mu minus 5mu

\begin{document}

\hed{Moles, Molar Mass, Mass Equations:}

\( M[\text{molar mass}] = n[\text{moles}]\cdot m[\text{mass}] \)
\medskip

\begin{tabular}{@{}c@{}}% center the two lines w.r.t. each other
  \(\displaystyle
    \frac{M}{m} = \frac{n\cdot m}{m}
    \Rightarrow
    \frac{M}{m} = \frac{n\cdot \cancel{m}}{\cancel{m}}
    \Rightarrow
    n = \frac{M}{m}
  \)\\[3ex]
  \boldmath\large
  \(\displaystyle
    n = \frac{M}{m}
  \)
\end{tabular}

\end{document}
4
  • 1
    +1 I hand over to you;-) Aug 13, 2023 at 16:48
  • @DavidCarlisle +10 to you: you really tried
    – gernot
    Aug 13, 2023 at 16:49
  • yes @DavidCarlisle you really went out of your way to help, again apologies for that headache
    – Nickotine
    Aug 13, 2023 at 16:59
  • thanks a lot @gernot
    – Nickotine
    Aug 13, 2023 at 16:59
5

You have specfied equations are flush left

\usepackage[fleqn]{mathtools}

To get a large bold centred equation use:

enter image description here

\documentclass{article}

\usepackage{mathtools}
\begin{document}


\[a\cdot a=b\]

{\huge\boldmath
\[a\cdot a=b\]
}

\medmuskip=50mu


{\huge\boldmath
\[a\cdot a=b\]

\[\frac{a\cdot a}{b}\]
$\frac{a\cdot a}{b}$
$\frac{a\;{\cdot}\; a}{b}$
}

\end{document}


Inline fractions use scriptsize numerators which do not get any space for binary operators so if you really need space use \; or (better) use \dfrac and display style fractions in textstyle

16
  • I removed fleqn, and using your code I still get the same result of the equation going to the far right, I'll show you the output and code, the code will have \cdot vs \cd in the 2nd equation and no matter how big I make the number, \cdot spacing is the same
    – Nickotine
    Aug 13, 2023 at 16:09
  • @Nickotine I added cdot and wide cdot to this answer Aug 13, 2023 at 16:15
  • @Nickotine ah sorry ok mathbin do not get space by default at scriptsize, so you could define \cd as \:{\cdot}\: Aug 13, 2023 at 16:21
  • I'll give it a go thanks for all your effort, much appreciated.
    – Nickotine
    Aug 13, 2023 at 16:23
  • I added a screenshot of the crappy behaviour I get @davidcarlisle
    – Nickotine
    Aug 13, 2023 at 16:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .