我写了这段代码
\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*}
得出以下方程
如何让所有行向量的相应元素水平对齐?
答案1
以下解决方案将每一列元素设置在 内,并对每一列\eqmathbox[<tag>]
使用相同的元素。<tag>
eqparbox
然后找出哪个元素的<tag>
宽度最大,并将它们全部放在这个最大宽度的框中。这样就可以水平排列。
\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}
另一种方法是将元素设置为固定宽度的列array
。这样可以让 TeX 计算出每列的宽度,从而更加方便。
答案2
您可以使用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}
如果你确实希望行向量条目对齐,
\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}