9

I wrote this code

\begin{flalign*}
    t\hphantom{^{\prime}}&=
        \begin{cases}
            \begin{pmatrix} 1 & 2 & ... & \frac{p}{2} & \frac{p}{2}+1 & ... & p \end{pmatrix} & \text{if $p$ even,} \\
            \begin{pmatrix} 1 & 2 & ... & \frac{p-1}{2} & \frac{p-1}{2}+1 & ... & p \end{pmatrix} & \text{if $p$ odd,}
        \end{cases}&&\\ 
    t^{\prime}&=
        \begin{cases}
            \begin{pmatrix} \frac{p}{2}+1 & \frac{p}{2}+2 & ... & p & 1 & ... & \frac{p}{2} \end{pmatrix} & \text{if $p$ even,} \\
            \begin{pmatrix} \frac{p-1}{2}+1 & \frac{p-1}{2}+2 & ... & p & 1 & ... & \frac{p-1}{2} \end{pmatrix} & \text{if $p$ odd.}
        \end{cases}&&
\end{flalign*}

which produces the following equations

enter image description here

How can I get respective elements of all row vectors to align horizontally?

Werner
  • 603,163

2 Answers2

8

You can use nicematrix:

\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}

\begin{document}

[ \begin{NiceArray}{@{} l @{\quad} l @{\qquad} l @{}} \Block{2-1}{t\hphantom{'} = {}} & \bigl(\begin{matrix} 1 & 2 & \dots & \frac{p}{2} & \frac{p}{2}+1 & \dots & p \end{matrix}\bigr) & \text{$p$ even,} \[1ex] & \bigl(\begin{matrix} 1 & 2 & \dots & \frac{p-1}{2} & \frac{p-1}{2}+1 & \dots & p \end{matrix}\bigr) & \text{$p$ odd,} \ \ \Block{2-1}{t' = {}} & \bigl(\begin{matrix} \frac{p}{2}+1 & \frac{p}{2}+2 & \dots & p & 1 & \dots & \frac{p}{2} \end{matrix}\bigr) & \text{$p$ even,} \[1ex] & \bigl(\begin{matrix} \frac{p-1}{2}+1 & \frac{p-1}{2}+2 & \dots & p & 1 & \dots & \frac{p-1}{2} \end{matrix}\bigr) & \text{$p$ odd.} \CodeAfter\SubMatrix{{1-2}{2-2}.\SubMatrix{{4-2}{5-2}. \end{NiceArray} ]

\end{document}

enter image description here

If you really want that the row vector entries are aligned,

\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}

\begin{document}

[ \begin{NiceArray}{ @{} l @{\quad} r @{} ccccccc @{} l @{\qquad} l @{} } \Block{2-1}{t\hphantom{'} = {}} & \big( & 1 & 2 & \dots & \frac{p}{2} & \frac{p}{2}+1 & \dots & p & \big) & \text{$p$ even,} \[1ex] & \big( & 1 & 2 & \dots & \frac{p-1}{2} & \frac{p-1}{2}+1 & \dots & p & \big) & \text{$p$ odd,} \ \ \Block{2-1}{t' = {}} & \big( & \frac{p}{2}+1 & \frac{p}{2}+2 & \dots & p & 1 & \dots & \frac{p}{2} & \big) & \text{$p$ even,} \[1ex] & \big( & \frac{p-1}{2}+1 & \frac{p-1}{2}+2 & \dots & p & 1 & \dots & \frac{p-1}{2} & \big) & \text{$p$ odd.} \CodeAfter\SubMatrix{{1-2}{2-2}.\SubMatrix{{4-2}{5-2}. \end{NiceArray} ]

\end{document}

enter image description here

egreg
  • 1,121,712
8

The following solution sets each column element inside an \eqmathbox[<tag>], using the same <tag> for each column. eqparbox then figures out which element with the same <tag> is the widest and sets them all in a box of this maximum-width. This allows things to line up horizontally.

enter image description here

\documentclass{article}

\usepackage{amsmath,eqparbox}

% https://tex.stackexchange.com/a/34412/5764 \makeatletter \NewDocumentCommand{\eqmathbox}{o O{c} m}{% \IfValueTF{#1} {\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}} {\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}} \mathpalette\eqmathbox@{#3} } \makeatother

\begin{document}

Original nonalignment: \begin{flalign} t\hphantom{^{\prime}}&= \begin{cases} \begin{pmatrix} 1 & 2 & \cdots & \frac{p}{2} & \frac{p}{2} + 1 & \cdots & p \end{pmatrix} & \text{if $p$ even,} \ \begin{pmatrix} 1 & 2 & \cdots & \frac{p - 1}{2} & \frac{p - 1}{2} + 1 & \cdots & p \end{pmatrix} & \text{if $p$ odd,} \end{cases}&&\ t^{\prime}&= \begin{cases} \begin{pmatrix} \frac{p}{2} + 1 & \frac{p}{2} + 2 & \cdots & p & 1 & \cdots & \frac{p}{2} \end{pmatrix} & \text{if $p$ even,} \ \begin{pmatrix} \frac{p-1}{2} + 1 & \frac{p - 1}{2} + 2 & \cdots & p & 1 & \cdots & \frac{p - 1}{2} \end{pmatrix} & \text{if $p$ odd.} \end{cases}&& \end{flalign}

Updated horizontal alignment: \begingroup \setlength{\arraycolsep}{0.5\arraycolsep}% \begin{flalign} t\hphantom{^{\prime}} &= \begin{cases} \begin{pmatrix} \eqmathbox[c1]{1} & \eqmathbox[c2]{2} & \eqmathbox[c3]{\cdots} & \eqmathbox[c4]{\frac{p}{2}} & \eqmathbox[c5]{\frac{p}{2} + 1} & \eqmathbox[c6]{\cdots} & \eqmathbox[c7]{p} \end{pmatrix} & \text{if $p$ even,} \ \begin{pmatrix} \eqmathbox[c1]{1} & \eqmathbox[c2]{2} & \eqmathbox[c3]{\cdots} & \eqmathbox[c4]{\frac{p - 1}{2}} & \eqmathbox[c5]{\frac{p - 1}{2} + 1} & \eqmathbox[c6]{\cdots} & \eqmathbox[c7]{p} \end{pmatrix} & \text{if $p$ odd,} \end{cases}&& \ t^{\prime} &= \begin{cases} \begin{pmatrix} \eqmathbox[c1]{\frac{p}{2} + 1} & \eqmathbox[c2]{\frac{p}{2} + 2} & \eqmathbox[c3]{\cdots} & \eqmathbox[c4]{p} & \eqmathbox[c5]{1} & \eqmathbox[c6]{\cdots} & \eqmathbox[c7]{\frac{p}{2}} \end{pmatrix} & \text{if $p$ even,} \ \begin{pmatrix} \eqmathbox[c1]{\frac{p - 1}{2} + 1} & \eqmathbox[c2]{\frac{p -1}{2} + 2} & \eqmathbox[c3]{\cdots} & \eqmathbox[c4]{p} & \eqmathbox[c5]{1} & \eqmathbox[c6]{\cdots} & \eqmathbox[c7]{\frac{p - 1}{2}} \end{pmatrix} & \text{if $p$ odd.} \end{cases}&& \end{flalign} \endgroup

\end{document}

An alternative would be to set the elements in a fixed-width column array. It's just convenient to let TeX figure out the widths of each column.

Werner
  • 603,163