Math & ScienceEquation not centered

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

Equation not centered

Post by Cham »

Hm, using this code is apparently a solution, but the equation number is placed on a second line.

Code: Select all

\begin{equation}
  \makebox[\textwidth]{
    \text{SOME VERY VERY LONG AND LARGE EQUATION}
  }
\end{equation}
I would prefer to have the equation number on the same line as the equation.


Edit:
Ooops ! Using 0pt instead of \textwidth apparently solves my issue.

I think that we now have a nice solution.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Equation not centered

Post by localghost »

Cham wrote:[…] I think that we now have a nice solution.
Indeed, if you consider anti-typographical typesetting as nice solution. m(
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Equation not centered

Post by Cham »

localghost wrote:
Cham wrote:[…] I think that we now have a nice solution.
Indeed, if you consider anti-typographical typesetting as nice solution. m(
Do you have a better solution ?
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Equation not centered

Post by cgnieder »

I believe the standard solution would be to split the equation into two lines:

Code: Select all

\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{textcomp}
\usepackage{amsmath}
\makeatletter
\renewcommand\theequation{\thesection.\arabic{equation}}
\@addtoreset{equation}{section}
\makeatother

\begin{document}
\chapter{Title}
\section{Section title}
\subsection{Subsection}
Bla bla bla bla
\begin{equation}
 \frac{1}{2}\Delta(f_{ij}f^{ij})= 2\left(\sum_{i<j}\chi_{ij}(\sigma_{i}-
   \sigma_{j})^{2}+f^{ij}\nabla_{j}\nabla_{i}(\Delta f)+\right.
   \left.+\nabla_{k}f_{ij}\nabla^{k}f^{ij}+
   f^{ij}f^{k}\left[2\nabla_{i}R_{jk}-\nabla_{k}R_{ij}\right]\vphantom{\sum_{i<j}}\right)
\end{equation}
Bla bla bla.
\begin{multline}
 \frac{1}{2}\Delta(f_{ij}f^{ij})= 2\left(\sum_{i<j}\chi_{ij}(\sigma_{i}-
   \sigma_{j})^{2}+f^{ij}\nabla_{j}\nabla_{i}(\Delta f)+\right.\\% <= note the linebreak
   \left.+\nabla_{k}f_{ij}\nabla^{k}f^{ij}+
   f^{ij}f^{k}\left[2\nabla_{i}R_{jk}-\nabla_{k}R_{ij}\right]\vphantom{\sum_{i<j}}\right)
\end{multline}
Bla bla bla.
\end{document}
See the mathmode document for details.

Regards
site moderator & package author
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Equation not centered

Post by Cham »

Well, spliting the equation isn't an option in this case. Here's a screen capture of my special case problem :
alignment.jpg
alignment.jpg (90.78 KiB) Viewed 5675 times
As you can see, the first equation isn't THAT long. There's plenty of space around it. The equation number at its right is a bit long (but it isn't exagerated either). Yet, LaTeX pushes the equation to the left, so there's exactly the same space around it, on the left and on the right. The equation isn't centered relative to the text, while the second (a bit shorter) equation is well centered relative to the text.

I don't like that at all. I want the first equation to stay centered relative to the text, exactly like the second equation. See the glitches that I indicated in red.

There's enough space at the right of the first equation, so there wont be any overlap with its number.

For unknown reason, the \makebox[0pt] command gives me a compilation error and I didn't found a way yet to solve this issue.

For comparison, here's the same text and equations, with a different chapter numerotation. I don't have the issue in this case. This is what I want LaTeX to do (in this case only !) :
picture2.jpg
picture2.jpg (77.01 KiB) Viewed 5675 times
Any idea ?
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Re: Equation not centered

Post by cgnieder »

Can you make an MWE containing these two equations showing the undesired behavior?

Regards
site moderator & package author
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Equation not centered

Post by Cham »

Here you go. This one exactly replicate the problem of the first equation.

Code: Select all

\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{textcomp}
\usepackage{amsmath}
\usepackage{tensor}
\makeatletter
\renewcommand\theequation{\thesection.\arabic{equation}}
\@addtoreset{equation}{section}
\makeatother

\begin{document}
\chapter{Title}
\section{Section title}
\subsection{Subsection}
Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
	\begin{equation}
		\frac{d^2 \, \displaystyle{\tensor{x}{^{\lambda}}}}{d\, \sigma^2} + \Gamma_{\mu \nu}^{\lambda} \; \frac{d\, \displaystyle{\tensor{x}{^{\mu}}}}{d\, \sigma} \, \frac{d\, \displaystyle{\tensor{x}{^{\nu}}}}{d\, \sigma} = \frac{d\, \displaystyle{\tensor{x}{^{\lambda}}}}{d\, \sigma} \, \frac{d\, }{d\, \sigma} \, \ln \sqrt{\, \tensor{g}{_{\mu \nu}} \; \frac{d\, \displaystyle{\tensor{x}{^{\mu}}}}{d\, \sigma} \, \frac{d\, \displaystyle{\tensor{x}{^{\nu}}}}{d\, \sigma}}.
	\end{equation}
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
	\begin{equation}
		\tensor{g}{_{\mu \nu}} \; \frac{d\, \displaystyle{\tensor{x}{^{\mu}}}}{d\, \sigma} \, \frac{d\, \displaystyle{\tensor{x}{^{\nu}}}}{d\, \sigma} = \tensor{g}{_{\mu \nu}} \; \frac{d\, \displaystyle{\tensor{x}{^{\mu}}}}{d\, \tau} \, \frac{d\, \displaystyle{\tensor{x}{^{\nu}}}}{d\, \tau} \, \Big( \, \frac{d\, \tau}{d\, \sigma} \Big)^{\! 2} \equiv \Big( \, \frac{d\, \tau}{d\, \sigma} \Big)^{\! 2}.
	\end{equation}
bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
\end{document}
Remove the section numbering, and the first equation move to the center (the second equation doesn't move). Add the section numbering, and the first equation is pushed to the left.

So the question is how to fix the first equation to the center (relative to the text) ?
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Re: Equation not centered

Post by cgnieder »

Indeed, how interesting... and strange I thought at first. But I'm willing to bet that this has to do with some minimum space between equation and number. I was unable however where this space is defined and thus how to modify it...

Hopefully someone else knows.

Regards
site moderator & package author
User avatar
justdeath
Posts: 69
Joined: Mon Sep 05, 2011 10:27 am

Equation not centered

Post by justdeath »

The problem is the tensor package. Replace all \tensor commands by g (or the required letter) and everything aligns fine. The package maintainer should fix his code.

Yeah, my mistake. It is a spacing problem.

With the following change it aligns fine:

Code: Select all

\renewcommand\theequation{\thesubsection.\arabic{equation}}
Not sure of the solution of the problem though.

jd
Last edited by justdeath on Sat Oct 13, 2012 6:38 pm, edited 2 times in total.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Equation not centered

Post by cgnieder »

justdeath wrote:The problem is the tensor package. Replace all \tensor commands by g (or the required letter) and everything aligns fine.
No, it doesn't... it is still shifted to the left with the bigger tag.

Regards
site moderator & package author
Post Reply