4

I want to be able to center inline displaystyle equations (I've seen this done in some math books). For example, with enumerate:

1)                                  [centered equation]

or with just a little bit of text to the left:

We have                            [centered equation 1]
so                                 [centered equation 2].

[MWE] Here is what I tried, but I don't really know what I'm doing:

\documentclass{article}
\usepackage{bm}

\begin{document}
\begin{enumerate}
\item \begin{centering}$\displaystyle \langle \bm{x},\bm{y} \rangle = 
    \sum\limits_{i=1}^n x_i y_i = \sum\limits_{i=1}^n y_i x_i = 
    \langle \bm{y},\bm{x} \rangle$.\end{centering}
\end{enumerate}
\end{document}
2
  • 3
    The fact it's done in books doesn't imply it's good style. See tex.stackexchange.com/questions/59995/…
    – egreg
    Jan 2, 2015 at 23:55
  • 1
    centering is not an environment. \centering or \begin{center}...\end{center}.
    – cfr
    Jan 3, 2015 at 1:06

3 Answers 3

3

Not that I recommend the approach aesthetically, but it can be done with stacks. The \stackon with the long "L" stackgap set to 0pt overlays the two stacking components. The \addstackgap adds a short "S" stackgap (default 3pt) above and below the result, to avoid cramping.

\documentclass{article}
\usepackage{stackengine}
\usepackage{lipsum}
\def\stacktype{L}
\setstackgap{L}{0pt}
\begin{document}
\lipsum[1]
\noindent\addstackgap{\stackon{$\displaystyle\frac{x+y}{z}$}{%
  \makebox[\textwidth][l]{We have}}}\par
\noindent\addstackgap{\stackon{\makebox[\textwidth][l]{so}}{%
  $\displaystyle c^2 = a^2 + b^2$}}\par
\lipsum[4]
\end{document}

enter image description here

3

A simple approach in LaTeX without packages could be a text without taking space with \rlap or \makebox and then center with \hfill, for example, if \parindent is not 0pt:

\noindent\rlap{some text}\hfill$...$}\hfill\mbox{}\par 

When the right text is too long, use a \parbox{length}{some text}

Note that next example use the bm package to reproduce the equation of the MWE and xcolor to enclose the equations in colored boxes (for a better visual testing) and two macros for easier typing, but obviously all of this is dispensable.

MWE

\documentclass{article}
\usepackage{xcolor,bm} 
\newcounter{myeq}
\setcounter{myeq}{0}
\def\NumEq#1{\noindent\rlap{\addtocounter{myeq}{1}{\themyeq})}%
\hfill\fcolorbox{green}{gray!10}{$\displaystyle#1$}\hfill\mbox{}\par} 
\def\SayEq#1#2{\noindent\rlap{#1}%
\hfill\fcolorbox{green}{gray!10}{$\displaystyle#2$}\hfill\mbox{}\par} 

\begin{document}

% only for easier testing 
{\color{green}
\centering center\\
\noindent\dotfill\rule[-21em]{.4pt}{22em}\dotfill}
\vspace{-19em}

%examples
\SayEq{Pretty definite integral}{\int_a^b f(x)\,dx}
\SayEq{\parbox{.2\linewidth}{\raggedright Whe have a long equation here}}{\langle \bm{x},\bm{y} \rangle = \sum\limits_{i=1}^n x_i y_i = \sum\limits_{i=1}^n y_i x_i = 
    \langle \bm{y},\bm{x} \rangle}
\NumEq{\frac{x+y}{z}}
\NumEq{c^2 = a^2 + b^2}

\end{document}
2

If you are not using \eqno in the equation then you can use simply \leqno primitive:

I want to be able to center inline displaystyle equations (I've seen this
done in some math books). For example, with enumerate:
$$
  \int_a^b f(x)\,dx
  \leqno 1)
$$
or with just a little bit of text to the left:
$$
  x+y\over z
  \leqno \hbox{We have}
$$
$$
  c^2 = a^2 + b^2
  \leqno \hbox{so}
$$
\bye

leqno

You must log in to answer this question.

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