Math & ScienceHow to center math items ?

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 center math items ?

Post by Cham »

I'm having some difficulties with centering math expressions. Here's a MWE :

Code: Select all

\documentclass[12pt,letterpaper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{mathtools}

\begin{document}

	\begin{align}
		AA,
		&& BBB, \nonumber \\ \\ \nonumber
		CCCCCC,
		&& DDDDD.
	\end{align}

\end{document}
Here's a preview :
pict.jpg
pict.jpg (8.84 KiB) Viewed 55552 times
Currently, the items are aligned to their right. How can I have them centered, instead of having them aligned ? I'm sure this is very basic but can't remember how to do it.

Recommended reading 2024:

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

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

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

How to center math items ?

Post by Stefan Kottwitz »

Simply use an array, such as

Code: Select all

\documentclass{article}
\begin{document}
  \begin{equation}
    \begin{array}{c@{\qquad}c}
      AA,      & BBB, \\
      CCCCCC,  & DDDDD.
    \end{array}
  \end{equation}
\end{document}
centering.png
centering.png (3.57 KiB) Viewed 55539 times
align is better for formulas with alignment at relation symbols, such as equation systems, but here there's no relation, so we don't need align.

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

Re: How to center math items ?

Post by Cham »

Thanks Stefan, it works.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

How to center math items ?

Post by Cham »

I really don't understand the array environment.

Now, I need to present four centered equations, with an aligned arrow between two of them, like this (currently, the arrows aren't aligned) :

Code: Select all

\documentclass[12pt,letterpaper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{mathtools}

\begin{document}

 	\begin{equation*}
	\begin{array}{c@{\qquad}c}
		A = B + C
		\qquad\Rightarrow
		& D = E - F, \\ \\
		G = H
		\qquad\Rightarrow
		& K = P + Q + M.
	\end{array}
	\end{equation*}

\end{document}
Here's a preview :
array.jpg
array.jpg (9.17 KiB) Viewed 55502 times
As you can see, the equations are centered as they should. However, the arrows aren't aligned in the middle.

How can I edit this code to align the arrows in the middle, while keeping the equations centered ?
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

How to center math items ?

Post by Cham »

Hmm, I may have found a solution. Please, could you confirm this is the proper way of doing this, since I really feel unconfortable with the array environment :

Code: Select all

	\begin{equation*}
	\begin{array}{c@{\qquad}c@{\qquad}c}
		A = B + C
		&\Rightarrow
		& D = E - F, \\ \\
		G = H
		&\Rightarrow
		& K = P + Q + M.
	\end{array}
	\end{equation*}
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How to center math items ?

Post by Johannes_B »

Simply think of array as the maths equivalent of tabular, which to tell the truth it really is.

Code: Select all

 \documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{gather*}
	\begin{array}{c@{\qquad}c@{\qquad}c}
		A = B + C
		&\Rightarrow
		& D = E - F, \\ \\
		G = H
		&\Rightarrow
		& K = P + Q + M.
	\end{array}\\
	\intertext{Now the seperator is combined by a space, an arrow 
	and another space}
	\begin{array}{c@{\qquad\Rightarrow\qquad}c}
		A = B + C & D = E - F, \\
		G = H     & K = P + Q + M.
	\end{array}\\
	\begin{array}{rl@{\qquad\Rightarrow\qquad}rl}
		A &= B + C& D &= E - F, \\ 
		G &= H    & K &= P + Q + M.
	\end{array}
\end{gather*}
\end{document}
Attachments
chamArray.png
chamArray.png (37.4 KiB) Viewed 55496 times
Last edited by Johannes_B on Tue Jun 24, 2014 7:47 pm, edited 1 time in total.
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
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: How to center math items ?

Post by Stefan Kottwitz »

Sure, the proper way is to define a column alignment for each column. The arrows shall be a column, not part of another column, so they can be aligned. As a result, you got three c columns, which is fine.

The second example by Johannes is more like a trick and useful if there's the same arrow in each row.

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

Re: How to center math items ?

Post by Cham »

The space is exagerated in the second example, just after the "A", "D", "G" and "K".

But thanks for the reply. I think my problem is solved.
Post Reply