6

How can I align multiple math blocks, such that each block is centered.

In my example the 1 should be printed centered above the 11 and so on.

I guess this can be done with minipages, but I believe there is an easier and nicer solution.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align*}
&1  & &2  & &3  & &4  & &5  & &6  & &7  & &8\\
&11 & &22 & &33 & &44 & &55 & &66 & &77 & &88
\end{align*}
\end{document}

3 Answers 3

4

How about a matrix environment:

\documentclass{article}
\usepackage{amsmath} % for 'matrix' env.
\begin{document}

\[ 
\begin{matrix}
 1  &2  &3  &4  &5  &6  &7  &8 \\
11 &22 &33 &44 &55 &66 &77 &88
\end{matrix} 
\]

\end{document}

To change the column spacing, modify the parameter \arraycolsep, as in

\setlength\arraycolsep{15pt} % default value: 5pt

Here are two more possibilities: (a) an array environment and (b) a tabular environment that uses a centered version of the p column type.

\documentclass{article}
\usepackage{array}
\setlength\arraycolsep{15pt} % default value: 5pt
\newcolumntype{C}[1]{>{\centering\arraybackslash$}p{#1}<{$}}
\begin{document}
\[
\begin{array}{*{8}{c}}
 1  &2  &3  &4  &5  &6  &7  &8 \\
11 &22 &33 &44 &55 &66 &77 &88
\end{array} 
\]

\begin{center}
\begin{tabular}{*{8}{C{1cm}}}
 1  &2  &3  &4  &5  &6  &7  &8 \\
11 &22 &33 &44 &55 &66 &77 &88
\end{tabular}
\end{center}
\end{document}

enter image description here

4
  • Is there a parameter like width=\textwidth (which would simulate aligned equations, wouldn't it?)
    – user1
    Oct 25, 2017 at 23:39
  • @Ben - Are you thinking of tabular environments and the p column type? I've posted an addendum to show making use of this idea.
    – Mico
    Oct 25, 2017 at 23:45
  • I thought of an other situation, where I only want to align 1 with 11, 2 with 22 and 3 with 33. align automatically sets the gap between the blocks to fit the hole \textwidth
    – user1
    Oct 25, 2017 at 23:55
  • @Ben - I’m afraid I didn’t understand that comment. Could you rephrase?
    – Mico
    Oct 26, 2017 at 1:44
3

Here, with a TABstack. The inter-column gap and inter-row baselinekip are readily settable

\documentclass{article}
\usepackage{tabstackengine}
\setstacktabbedgap{8pt}% BETWEEN-COLUMN GAP
\setstackgap{L}{1.2\baselineskip}% BETWEEN ROW SKIP
\begin{document}
\tabbedCenterstack{
1  &2  &3  &4  &5  &6  &7  &8\\
11 &22 &33 &44 &55 &66 &77 &88
}
\end{document}

enter image description here

The cells are here set in text mode, but that default can be changed with \stackMath (or \TABstackMath).

Based on the OP's follow up comment, I was astounded to find (in my own package no less) that I can set the inter-column stack gap to \fill to achieve a full-width solution:

\documentclass{article}
\usepackage{tabstackengine,lipsum}
\setstacktabbedgap{\fill}% BETWEEN-COLUMN GAP
\setstackgap{L}{1.2\baselineskip}% BETWEEN ROW SKIP
\begin{document}
\noindent\tabbedCenterstack{
1  &2  &3  &4  &5  &6  &7  &8\\
11 &22 &33 &44 &55 &66 &77 &88
}\medskip

\lipsum[1]
\end{document}

enter image description here

2
  • Please see my comments to @Mico's solution.
    – user1
    Oct 25, 2017 at 23:57
  • @Ben Thanks for making me think harder on that question. I found that I can simply achieve a full-width solution wtih \setstacktabbedgap{\fill}. Oct 27, 2017 at 17:06
2

The following uses tabularx to set a \textwidth-wide table, with each column having the same width with a centred alignment, containing math content in \displaystyle. This matches to some extent what is provided by align* with the requirement of spreading out the content across the text block (or whatever width you supply):

enter image description here

\documentclass{article}

\usepackage{amsmath,tabularx}
\newcolumntype{M}{>{\centering\arraybackslash$\displaystyle}X<{$}}

\begin{document}

\begin{align*}
  &1  & &2  & &3  & &4  & &5  & &6  & &7  & &8  \\
  &11 & &22 & &33 & &44 & &55 & &66 & &77 & &88
\end{align*}

\[
  \begin{tabularx}{\textwidth}{ *{8}{M} }
    1  & 2  & 3  & 4  & 5  & 6  & 7  & 8  \\[\jot]
    11 & 22 & 33 & 44 & 55 & 66 & 77 & 88
  \end{tabularx}
\]

\[
  \begin{tabularx}{\textwidth}{ *{4}{M} }
    1  & 2  & 3  & 4  \\[\jot]
    11 & 22 & 33 & 44
  \end{tabularx}
\]

\[
  \begin{tabularx}{\textwidth}{ *{4}{M} }
    abcdef  &    4567    & qrstuvwxy  & 90  \\[\jot]
     123    & ghijklmnop &     8      & z
  \end{tabularx}
\]

\end{document}
2
  • Placing full-width tabularx environments inside unnumbered display-math environments seems like overkill. Prefacing then with \noindent instructions should suffice, right?
    – Mico
    Oct 26, 2017 at 7:53
  • 1
    @Mico: Indeed. The motivation for keeping them inside a display math environment is to ensure similar spacing around a mathematically-filled structure.
    – Werner
    Oct 26, 2017 at 15:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .