Math & Science ⇒ Equation not centered
- localghost
- Site Moderator
- Posts: 9201
- Joined: Fri Feb 02, 2007 12:06 pm
Re: Equation not centered
Since this is the common way to go, his solution is absolutely reliable. Nothing to be afraid of. Your machine won't blow up.
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
Board Rules
Avoidable Mistakes[/size]
¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Equation not centered
Well, you don't have to but if you look at the definition ofCham wrote:Hmmm, yes. But I must admit that I'm pretty nervous about modifying my preamble, because my document is now so large and complex, I don't want to mess with this huge castle of cards.cgnieder wrote: You can replace this withIt has the same effect.Code: Select all
\numberwithin{equation}{section}
Changing just a single line of code in the preamble may have HUGE consequences on the whole document.
\numberwithin
you'll see that it does exactly the same except for checking if the counters exist.
Code: Select all
\newcommand{\numberwithin}[3][\arabic]{%
\@ifundefined{c@#2}{\@nocounterr{#2}}{%
\@ifundefined{c@#3}{\@nocnterr{#3}}{%
\@addtoreset{#2}{#3}%
\@xp\xdef\csname the#2\endcsname{%
\@xp\@nx\csname the#3\endcsname .\@nx#1{#2}}}}%
}
\@xp
is an alias for \expandafter
and \@nx
another one for \noexpand
.Regards
site moderator & package author
Equation not centered
Hmm, this is what makes me a bit nervous. What does this implies ?cgnieder wrote:that it does exactly the same except for checking if the counters exist.
I don't think this should be a concern in my case, but...
Equation not centered
If you use
Regards
\numberwithin{equation}{section}
it checks for the counters equation
and section
. Since both exist nothing happens. But as I said: you don't have to replace your code. Since it is the same it really doesn't matter.Regards
site moderator & package author
Equation not centered
Ok, thanks a lot for your help guys, it's really appreciated.
I consider my issue solved.
EDIT : Hmmm, not exactly. There's still a glitch, described in my next message below...

I consider my issue solved.

EDIT : Hmmm, not exactly. There's still a glitch, described in my next message below...
Equation not centered
Guys, I noticed a small glitch with the previous solution. Here's again the code example which solves my previous issue, but notice the small indent there's on the first text line just after the first equation. There shoulnd't be any indent there.
Adding \noindent doesn't do anything.
What is happening here ?
Adding \noindent doesn't do anything.
What is happening here ?
Code: Select all
\documentclass{book}
\usepackage{mathtools}
\usepackage{tensor}
\newtagform{nospace}[\llap\bgroup(]{}{\egroup)}
\numberwithin{equation}{section}
\usepackage[nopar]{lipsum}% for dummy text
\begin{document}
\chapter{Blah}
\section{Blub}
\lipsum[4]
\usetagform{nospace}
\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}
\usetagform{default}
\lipsum[4]
\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}
\lipsum[4]
\end{document}
Equation not centered
Try writing
Notice the comment character! You might know (and if not it's good you learn now) that the end of a line is interpreted like a blank by TeX. So
is equivalent to
Regards
Code: Select all
\usetagform{default}%
Code: Select all
\usetagform{default}
Some text
Code: Select all
\usetagform{default} Some text
site moderator & package author
Equation not centered
Oh boy ! Thanks for that one.
Then this brings me another question, about the % at the end of the command line :
I believed that the % was used only to add some comments to the code, like this :
Now, apparently, there are other uses for that symbol ? Is that right ? I'm not sure I understand.

Then this brings me another question, about the % at the end of the command line :
I believed that the % was used only to add some comments to the code, like this :
Code: Select all
\noindent % A comment about this command
Some text...
Equation not centered
Well, the comment char tells TeX to ignore the rest of the line beginning with the comment char itself. This is of course quite handy to add information to the source that's not supposed to be part of the actual document. It can however also be used to hide the and of a line. When TeX finds the end of a line it actually finds the “end of line char” which is the converted into a space (or in case an empty line follows the end of the line a
is the same as
but
is the same as
and
is the same as
Regards
\par
token is inserted). This is why
Code: Select all
\usetagform{default}%
Some text
Code: Select all
\usetagform{default}Some text
Code: Select all
\usetagform{default}
Some text
Code: Select all
\usetagform{default} Some text
Code: Select all
\usetagform{default}
Some text
Code: Select all
\usetagform{default}\par Some text
site moderator & package author
Re: Equation not centered
Ok, thanks. This is now perfectly clear.
The case is now fully solved.
The case is now fully solved.