Math & ScienceAlign items center

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

Align items center

Post by Cham »

How can I align an odd number of items without any "=" sign, so the items are centered ?

Here's a working minimal example to work with :

Code: Select all

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

\begin{document}

Test
	\begin{align*}
		&ABC,
		&FGAW,
		&&NHYUR, \\ \\
		&QWEGH,
		&
		&&FGH.
	\end{align*}

\end{document}

Preview :
align.jpg
align.jpg (10.57 KiB) Viewed 3264 times
As you can see, the items aren't centered. I would like them to be centered on top of each other.
The one in the middle should stay in the middle.

Recommended reading 2024:

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

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

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

Align items center

Post by Cham »

There's a way to center the items, using the gathered environment, but I think it's "unnatural" :

Code: Select all

\documentclass[12pt,letterpaper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\begin{document}
Test
	\begin{align}
	&\begin{gathered}
		ABC, \\[16pt]
		QWEGH,
	\end{gathered}
	&\begin{gathered}
		FGAW, \\[16pt]
		{}
	\end{gathered}
	&&\begin{gathered}
		NHYUR, \\[16pt]
		FGH.
	\end{gathered}
	\end{align}
\end{document}
EDIT : There's also this variation :

Code: Select all

\documentclass[12pt,letterpaper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\begin{document}
Test
	\begin{align}
	&\begin{gathered}
		ABC, \\
		{} \\
		QWEGH,
	\end{gathered}
	&\begin{gathered}
		{} \\
		FGAW, \\
		{}
	\end{gathered}
	&&\begin{gathered}
		NHYUR, \\
		{} \\
		FGH.
	\end{gathered}
	\end{align}
\end{document}
I feel this is a bit complicated for what I'm trying to do. What is the proper way of doing this ?
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Align items center

Post by cgnieder »

Seems to me you want an {array} (the equivalent of a {tabular} in math mode):

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
Test
\begin{equation}
  \begin{array}{c@{\qquad}c@{\qquad}c}
    ABC,   & FGAW, & NHYUR, \\[16pt]
    QWEGH, &       & FGH.
  \end{array}
\end{equation}
\end{document}
Regards
site moderator & package author
Post Reply