这是我的代码:
P_{i, j} = \begin{pmatrix}
1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & \ddots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\
\vdots & 0 & 0 & \dots & \dots & 1 & \vdots & \vdots & (\text{ligne } i)\\
\vdots & \vdots & \vdots & 1 & 0 & 0 & \vdots & \vdots \\
\vdots & \vdots & \vdots & 0 & \ddots & \vdots & \vdots & \vdots \\
\vdots & \vdots & 1 & 0 & \dots & 0 & \dots & 0 & (\text{ligne } j) \\
\vdots & \vdots & 0 & \vdots & 0 & \vdots & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 1
\end{pmatrix}
我希望文本位于矩阵旁边,括号外面,但高度与现在相同。
答案1
有了这个包nicematrix
,您只需改变您的环境{pmatrix}
并{pNiceMatrix}
添加密钥last-col
。
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
$P_{i, j} = \begin{pNiceMatrix}[last-col]
1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & \ddots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\
\vdots & 0 & 0 & \dots & \dots & 1 & \vdots & \vdots & (\text{ligne } i)\\
\vdots & \vdots & \vdots & 1 & 0 & 0 & \vdots & \vdots \\
\vdots & \vdots & \vdots & 0 & \ddots & \vdots & \vdots & \vdots \\
\vdots & \vdots & 1 & 0 & \dots & 0 & \dots & 0 & (\text{ligne } j) \\
\vdots & \vdots & 0 & \vdots & 0 & \vdots & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 1
\end{pNiceMatrix}$
\end{document}
这是表示转置矩阵的另一种方法(也用nicematrix
)。
\documentclass{article}
\usepackage{nicematrix,tikz}
\begin{document}
\NiceMatrixOptions{code-for-first-row = \scriptstyle,code-for-first-col = \scriptstyle }
\setcounter{MaxMatrixCols}{12}
\newcommand{\blue}{\color{blue}}
\[P_{i,j} = \begin{pNiceMatrix}[last-row,last-col,nullify-dots,xdots/line-style={dashed,blue}]
1& & & \Vdots & & & & \Vdots \\
& \Ddots[line-style=standard] \\
& & 1 \\
\Cdots[color=blue,line-style=dashed]& & & \blue 0 &
\Cdots & & & \blue 1 & & & \Cdots & \blue \leftarrow i \\
& & & & 1 \\
& & &\Vdots & & \Ddots[line-style=standard] & & \Vdots \\
& & & & & & 1 \\
\Cdots & & & \blue 1 & \Cdots & & \Cdots & \blue 0 & & & \Cdots & \blue \leftarrow j \\
& & & & & & & & 1 \\
& & & & & & & & & \Ddots[line-style=standard] \\
& & & \Vdots & & & & \Vdots & & & 1 \\
& & & \blue \overset{\uparrow}{i} & & & & \blue \overset{\uparrow}{j} \\
\end{pNiceMatrix}\]
\end{document}
您需要多次编译(因为使用了 PGF/Tikz 节点nicematrix
)。
答案2
如果不添加任何额外的包,您必须添加另一个相邻矩阵并确保该矩阵中的垂直间距与左侧矩阵中的垂直间距相同。这需要一点工作。一种方法是使用\vphantom{}
,它不排版任何内容,根本不占用水平空间,但仍让 LaTeX 计算其参数占用的垂直空间。
我也会基于array
而不是bmatrix
、pmatrx
或来制定解决方案matrix
。它可以更好地控制对齐和间距,同时仍然可以添加任何类型的缩放括号。
\documentclass[journal]{IEEEtran}
\usepackage{array}
\usepackage{mleftright}
\usepackage{mathtools}
\AtBeginDocument{\mleftright}
\setlength\arraycolsep{6pt}
\begin{document}
\[
P_{i, j} =
\left( % Auto-scaled open bracket
\begin{array}{
@{\hspace{6pt}} % set space between left bracket and the first column
*8{c}
@{\hspace{6pt}}} % as above but set space between the last column and the right bracket
1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & \ddots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\
\vdots & 0 & 0 & \dots & \dots & 1 & \vdots & \vdots \\
\vdots & \vdots & \vdots & 1 & 0 & 0 & \vdots & \vdots \\
\vdots & \vdots & \vdots & 0 & \ddots & \vdots & \vdots & \vdots \\
\vdots & \vdots & 1 & 0 & \dots & 0 & \dots & 0 \\
\vdots & \vdots & 0 & \vdots & 0 & \vdots & 1 & 0 \\
\vphantom{\vdots}
0 & 0 & 0 & 0 & 0 & 0 & 0 & 1
\end{array}
\right) % Auto-scaled closing bracket
\hspace{1em} % space between two arrays
\begin{array}{
@{} % set no space between columns
>{\vphantom{\vdots}} % ensures the vertical spacing
l
@{} % - the same as above
l
@{} % - the same as above
}
\multicolumn{1}{@{}c@{}}{} & \\% cancels an effect of \vphantom{\vdots} in this row
& \\
& (\text{ligne } i)\\
& \\
& \\
& (\text{ligne } j) \\
& \\
& \\
\end{array}
\]
\end{document}
答案3
这段代码不是最好的,但它可以在没有新包的情况下工作
$
P_{i, j} = \begin{pmatrix}
1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & \ddots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\
\vdots & 0 & 0 & \dots & \dots & 1 & \vdots & \vdots &\\
\vdots & \vdots & \vdots & 1 & 0 & 0 & \vdots & \vdots \\
\vdots & \vdots & \vdots & 0 & \ddots & \vdots & \vdots & \vdots \\
\vdots & \vdots & 1 & 0 & \dots & 0 & \dots & 0 & \\
\vdots & \vdots & 0 & \vdots & 0 & \vdots & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 1
\end{pmatrix}
\begin{matrix}
\vphantom{0}\\
\vphantom{\vdots}\\
\vphantom{\vdots}(\text{ligne } i)\\
\vphantom{\vdots}\\
\vphantom{\vdots}\\
\vphantom{\vdots}(\text{ligne } j)\\
\vphantom{\vdots}\\
\vphantom{0}\\
\end{matrix}
$