Math & ScienceHow to left align some equations under a centered equation ?

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

How to left align some equations under a centered equation ?

Post by Cham »

I'm experiencing difficulties in aligning some equations inside a single block. Here's a MWE showing the problem and its preview :

Code: Select all

\documentclass[12pt,letterpaper,twoside]{book}
\usepackage{lmodern}
\usepackage{amsmath}

\begin{document}

	\begin{gather}
		A + B + C = D - E - F \nonumber \\[18pt]
	\begin{align}
		&= G - H + K + X + Y + Z + P + Q + R + S + T \nonumber \\[18pt]
		&\equiv L + M + N + U + V + W \nonumber \\[18pt]
		&\equiv P - Q. \label{label name}
	\end{align}
	\end{gather}

\end{document}
Preview :
label.jpg
label.jpg (15.53 KiB) Viewed 25559 times
Here are the real equations. The distribution is the same as what the code above is doing :
equs.jpg
equs.jpg (33.93 KiB) Viewed 25559 times
I need the first line to be centered, and the three last lines to be left aligned, like what is shown here. The last line need a number and a label. Currently, the code above works, but it gives a duplicate label warning during compilation (multiply defined label).

So how can I do this properly ? Whatever what I'm doing doesn't work ! :cry:

Using aligned instead of align removes the number !
Last edited by Cham on Wed Jul 06, 2016 2:31 pm, edited 6 times in total.

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How to left align some equations under a centered equation ?

Post by Johannes_B »

Like that?

Code: Select all

\documentclass[12pt,letterpaper,twoside]{book}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{showframe}

\begin{document}

	\begin{align}
	&A + B + C = D - E - F \nonumber \\
		&= G - H + K \nonumber \\
		&\equiv L + M + N \nonumber \\
		&\equiv P - Q. \label{label_nameA}
	\end{align}
	\begin{align}
	A + B + C &= D - E - F \nonumber \\
		&= G - H + K \nonumber \\
		&\equiv L + M + N \nonumber \\
		&\equiv P - Q. \label{label_nameB}
	\end{align}

\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

How to left align some equations under a centered equation ?

Post by Cham »

The first line isn't centered, as asked. The problem is the real equations are pretty long, so I can't align the first line with the others (and it would be ugly anyway). It needs to be centered.

I was thinking about wrapping the whole first line with \mathclap, and use some space before it to push the equation to the right, but this would be an hack done by eye.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: How to left align some equations under a centered equati

Post by Johannes_B »

I see the first line centered in my example. But your problem seems to be unrelated to the example you have posted, how should i have known?

Please post an example, that really shows your troubles.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: How to left align some equations under a centered equati

Post by Cham »

In your code above, the first line is NOT horizontally centered on the page (it just appears to be centered because the second line is really short). It is aligned to the left of the other lines below it (A is aligned with the equal sign below it, in the first example you gave). Or its equal sign is aligned with the other equal signs, in your second example. I can't use this in my specific problem, since my real second equation is much longer than the first line equation.

I've edited the code in my first message. Try it in overleaf. It's working (it is doing exactly what I want to do !), but when I compile it on my computer, I get a warning message about duplicate labels (multiply defined labels).

Should I just ignore these duplicate warning messages ? (I suspect I shouldn't ignore them)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Re: How to left align some equations under a centered equati

Post by Stefan Kottwitz »

Hi Cham,

I see the first line as centered. It's centered to the text area, not to the page.

If you edit the code in the first post, both the first post and the screenshot are wrong. So I and other readers may not understand all what's going on. Could you restore the code in the post above and post the code in a later post? So we see the origin and the progress. And it would be better to see the real equation instead of dummy symbols. It's more fun, to see science.

The duplicate label message indicates a problem. That's because you nested align and gather which is not intended this way and can lead to further issues, such as with spacing.

Perhaps post the code status with a real equation, and we take a look again to improve it?

Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

How to left align some equations under a centered equation ?

Post by Cham »

Stefan,

I've edited the first message to show the preview which goes with the code. Below it are the real equations, which are distributed the same way. I don't see how to distribute them differently (centering all the lines would be really ugly).

So how should I remove the warning message, while maintaining that particular distribution ?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

How to left align some equations under a centered equation ?

Post by Stefan Kottwitz »

It could be as simple as:

Code: Select all

\[
  A + B + C = D - E - F\\[5pt]
\]
\begin{align}
  &= G - H + K + X + Y + Z + P + Q + R + S + T \nonumber \\[18pt]
  &\equiv L + M + N + U + V + W \nonumber \\[18pt]
  &\equiv P - Q. \label{label name}
\end{align}
The 5pt are 18pt minus \jot=3pt minus 10pt (I think that's the skip after a displayed math environment).

Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

How to left align some equations under a centered equation ?

Post by Cham »

Thanks for the suggestion, Stefan.

What is the \[ \] environement ? If there's a page change between both blocks, the whole will not stay together on the same page, right ?

Is \[ \] exactly the same as a \begin{equation*} \end{equation*} ?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

How to left align some equations under a centered equation ?

Post by Stefan Kottwitz »

That's correct, both.

Page breaks could be prevented, such as by a minipage or samepage environment, or a needspace command.

Stefan
LaTeX.org admin
Post Reply