Math & ScienceCentered Equation aligned with a Line of Text

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Centered Equation aligned with a Line of Text

Post by Cham »

Very often, I would like to write an equation after a line of text, with the equation on the same line as the text while horizontally centered on the page and its eq:number appearing on the right side. I don't want LaTeX to reduce the size of the equation, since there's just a single line of text on the same line as the equation. How is that possible ?

To be clear, here's an example of what I would like to do (this was done with an old word processor) :
equations.jpg
equations.jpg (55.92 KiB) Viewed 3307 times
How to tell LaTeX that the integral should be on the same baseline as the text on its left (I hand added a red horizontal bar on the picture, as a reference), while staying aligned with the equation below it, and no vertical compression at all ?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Centered Equation aligned with a Line of Text

Post by localghost »

It can be done with some negative vertical space. But from my point of view it doesn't look really good.

Code: Select all

\documentclass[11pt,a4paper,french]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{geometry}
\usepackage{mathtools}   % loads »amsmath«

\let\vec\mathbf  % Change appearance of vectors, try \underline here instead of \mathbf

\begin{document}
  de référence arbitraire situé dans la distribution. Le potentiel scalaire peut s'écrire comme suit:
  \begin{align}
    \phi(\vec{r}) &\approx \phi(\vec{r}_0)+(\vec{r}-\vec{r}_0)\cdot\nabla\phi(\vec{r})\big|_{r_0} \\
    &= \phi(\vec{r}_0)+\vec{r}_0\cdot\vec{E}(\vec{r})-\vec{r}\cdot\vec{E}(\vec{r}) \\
  \end{align}
  Ainsi, on a\vspace{-2.15\baselineskip}
  \begin{align}
    U &\approx \int \bigl(\phi(\vec{r}_0)+\vec{r}_0\cdot\vec{E}(\vec{r})-\vec{r}\cdot\vec{E}(\vec{r})\bigr)\rho\,d^3x \\
    &= \bigl(\phi(\vec{r}_0)+\vec{r}_0\cdot\vec{E}(\vec{r}_0)\bigr)\int\rho\,d^3x-\int\rho\,\vec{r}\cdot\vec{E}(\vec{r}_0)\,d^3x
  \end{align}
  La première intégrale s'élimine pour les distributions caracterisées par une charge électrique totale null.
\end{document}
The disadvantage is that you have to adjust this vertical space by hand. I would prefer the common layout, that is to say all the equations aligned with some short text between them.

Code: Select all

\documentclass[11pt,a4paper,french]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{geometry}
\usepackage{mathtools}

\let\vec\mathbf  % Change appearance of vectors, try \underline here instead of \mathbf

\begin{document}
  de référence arbitraire situé dans la distribution. Le potentiel scalaire peut s'écrire comme suit:
  \begin{align}
    \phi(\vec{r}) &\approx \phi(\vec{r}_0)+(\vec{r}-\vec{r}_0)\cdot\nabla\phi(\vec{r})\big|_{r_0} \\
    &= \phi(\vec{r}_0)+\vec{r}_0\cdot\vec{E}(\vec{r})-\vec{r}\cdot\vec{E}(\vec{r}) \\
    \shortintertext{Ainsi, on a}
    U &\approx \int \bigl(\phi(\vec{r}_0)+\vec{r}_0\cdot\vec{E}(\vec{r})-\vec{r}\cdot\vec{E}(\vec{r})\bigr)\rho\,d^3x \\
    &= \bigl(\phi(\vec{r}_0)+\vec{r}_0\cdot\vec{E}(\vec{r}_0)\bigr)\int\rho\,d^3x-\int\rho\,\vec{r}\cdot\vec{E}(\vec{r}_0)\,d^3x
  \end{align}
  La première intégrale s'élimine pour les distributions caracterisées par une charge électrique totale null.
\end{document}

Thorsten
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Centered Equation aligned with a Line of Text

Post by Cham »

I agree that we shouldn't adjust the vertical position by hand, so the first solution isn't satisfying.

In the case of the second solution, the inserted short text isn't aligned with the integral equation. After a compilation on my system, it appears at the standard position with the equation below it.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Centered Equation aligned with a Line of Text

Post by localghost »

Cham wrote:[…] In the case of the second solution, the inserted short text isn't aligned with the integral equation. After a compilation on my system, it appears at the standard position with the equation below it.
I know. I don't consider the layout of word processors as benchmark. This is my share. And I can't offer alternatives.
Post Reply