Math & Scienceamsmath with multiple alignments on one line, centered

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
x42bn6
Posts: 14
Joined: Tue Apr 07, 2009 1:35 am

amsmath with multiple alignments on one line, centered

Post by x42bn6 »

Hi all,

Let's just say I want to typeset, ASCII-art style:

Code: Select all

0 <  a  <  b  < 1
1 < a+1 < b+1 < 2
Where the alignments are on the < characters and the contents a, b, a+1 and b+1 are centred in their "cells", but 0, 1, 1 and 2 are right- or left-aligned as if they were the standard align environment.

For example, if I were to put this into a matrix or array environment:

Code: Select all

\begin{array}{rcccccl}
0 & < & a   & < & b   & < & 1 \\
1 & < & a+1 & < & b+1 & < & 2
\end{array}
Of course, this doesn't preserve the intra-line spacing as it's a matrix not an environment like align or alignat. But I think it gets across what I'm trying to do.

Is it possible?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

amsmath with multiple alignments on one line, centered

Post by frabjous »

I'm not entirely sure what you're trying to do. Is the problem with yours just too much space between the "cells"? What about something along these lines?

Code: Select all

\begin{array}{r@{\:<\:}c@{\:<\:}c@{\:<\:}l}
0 & a   &  b   & 1 \\
1 & a+1 &  b+1 & 2
\end{array}
x42bn6
Posts: 14
Joined: Tue Apr 07, 2009 1:35 am

Re: amsmath with multiple alignments on one line, centered

Post by x42bn6 »

Yes, but not with an array (because the between-line spacing is different for an array and, say, align - stick a \dfrac both lines in the same cell and they're too close).
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

amsmath with multiple alignments on one line, centered

Post by frabjous »

You can increase the vertical space between the lines in the array by specifying the length after the line break \\:

Code: Select all

\begin{array}{r@{\:<\:}c@{\:<\:}c@{\:<\:}l}
0 & a   &  b   & \dfrac{1}{2} \\[3ex]
1 & a+1 &  b+1 & \dfrac{3}{2}
\end{array}
Alternatively you could load the array package and set the length extrarowheight:

Code: Select all

\documentclass{article}
\usepackage{amsmath,array}
\begin{document}
\setlength{\extrarowheight}{2ex}
\[
\begin{array}{r@{\:<\:}c@{\:<\:}c@{\:<\:}l}
0 & a   &  b   & \dfrac{1}{2} \\
1 & a+1 &  b+1 & \dfrac{3}{2}
\end{array}
\]
\end{document}
x42bn6
Posts: 14
Joined: Tue Apr 07, 2009 1:35 am

Re: amsmath with multiple alignments on one line, centered

Post by x42bn6 »

Do I really have to hack around it?

And is that the space which corresponds to the space in the environments in amsmath?
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Re: amsmath with multiple alignments on one line, centered

Post by frabjous »

Did you see my second suggestion?

I don't know if there are other options, and I don't know what the space is in align environments in AMSMath. Someone else may have some further ideas, but I really don't see this as a hack.
Post Reply