
我需要將一個2x2矩陣均勻地插入到5x5矩陣的第4行和第5行以及第4行和第5列。我的程式碼需要調整。
\begin{equation*}
a_1=
\begin{bmatrix}
1 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & & {\begin{bmatrix} & b & \end{bmatrix}}\\
0 & 0 & 0 &
\end{bmatrix}
\end{equation*}
答案1
或者也許與nicematrix
.它確實需要一個額外的包(這又會加載其他東西,最突出的是 TikZ),但列之間的間距不會被修改,並且您可以完全控制外觀的各個方面。
\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}
\begin{document}
\begin{equation*}
a_1=\begin{bNiceMatrix}[name=mymatrix]
1 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & \phantom{0} & \phantom{0}\\
0 & 0 & 0 & \phantom{0} & \phantom{0}
\end{bNiceMatrix}
\begin{tikzpicture}[remember picture,overlay]
\node[fit=(mymatrix-4-4)(mymatrix-5-5),inner sep=-0.2ex,text height=1.2em] (f){$b$};
\draw[thick] ([xshift=0.5ex]f.south west)-| (f.north west) -- ++ (0.5ex,0)
([xshift=-0.5ex]f.south east)-| (f.north east) -- ++ (-0.5ex,0);
\end{tikzpicture}
\end{equation*}
\end{document}
答案2
我使用的不是bmatrix
2x2 矩陣matrix
。但這只是個人喜好,可以毫無問題地互換。
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
a_1=
\begin{bmatrix}
\begin{matrix}
1 & 0 & 0\\
0 & 0 & 0 \\
0 & 0 & 0
\end{matrix} &
\begin{matrix}
0 & 0\\
0 & 0 \\
0 & 0
\end{matrix}\\
\begin{matrix}
0 & 0 & 0\\
0 & 0 & 0
\end{matrix} &
\begin{matrix} & b & \end{matrix}\\
\end{bmatrix}
\end{equation*}
\end{document}
結果matrix
:
結果bmatrix
:
答案3
解決方案blkarray
:
\documentclass{article}
\usepackage{multirow}
\usepackage{blkarray, bigstrut}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
a_1=
\left[
\begin{blockarray}{@{\,}ccccc@{\:}}
\bigstrut[t]
1 & 0 & 0 & 0 & 0 & \\
0 & 0 & 0 & 0 & 0 & \\
0 & 0 & 0 & 0 & 0 & \\
\begin{block}{@{\,}ccc[\BAmulticolumn{2}{!{}c!{}}@{\:}]}
0 & 0 & 0 & \multirow{2}{*}{b}\\
0 & 0 & 0 & \\
\end{block}
\BAnoalign{\vskip -7ex}
\end{blockarray}\right]
\end{equation*}
\end{document}