我正在尝试实现类似下图的表格。我几乎已经做到了,但我不知道如何将带有“a_{1n} ...”的行放在矩阵下方,以便与行匹配。
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,matrix}
\tikzset{
table/.style={
matrix of math nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={rectangle,text width=3em,align=center},
text depth=1.25ex,
text height=2.5ex,
nodes in empty cells,
left delimiter=[,
right delimiter={]},
ampersand replacement=\&
}
}
\begin{document}
\[
A=
\begin{tikzpicture}[baseline,decoration=brace]
\matrix (m) [table] {
1 \& 0 \& \cdots \& 0 \& \lvert \& 1 \& 1 \& \cdots \& 1 \\
0 \& 1 \& \cdots \& 0 \& \lvert \& 0 \& 0 \& \cdots \& 0 \\
\vdots \& \vdots \& \ddots \& 0 \& \lvert \& \vdots \& \vdots \&\ddots\& \vdots \\
0 \& 0 \& \cdots \& 1 \& \lvert \& 0 \& 0 \& \cdots \& 0 \\
\textrm{--} \& \textrm{--} \& \textrm{--} \& \textrm{--} \& \textrm{--}\& \textrm{--} \& \textrm{--} \& \textrm{--} \& \textrm{--} \\
0 \& 0 \& \cdots \& 0 \& \lvert \& 1 \& 0 \& \cdots \& 1 \\
0 \& 0 \& \cdots \& 0 \& \lvert \& 0 \& 1 \& \cdots \& 0 \\
\vdots \& \vdots \& \ddots \& 0 \& \lvert \& \vdots \& \vdots \&\ddots\& \vdots \\
1 \& 1 \& \cdots \& 1 \& \lvert \& 0 \& 0 \& \cdots \& 1 \\
};
\draw[decorate,transform canvas={xshift=-1.4em},thick] (m-4-1.south west) -- node[left=2pt] {$m$} (m-1-1.north west);
\draw[decorate,transform canvas={xshift=-1.4em},thick] (m-9-1.south west) -- node[left=2pt] {$n$} (m-6-1.north west);
\draw[decorate,transform canvas={yshift=0.5em},thick] (m-1-1.north west) -- node[above=2pt] {$m$} (m-1-4.north east);
\draw[decorate,transform canvas={yshift=0.5em},thick] (m-1-6.north west) -- node[above=2pt] {$n-1$} (m-1-9.north east);
\end{tikzpicture}
\]
\end{document}
答案1
以下是两种解决方案:
- 第一个完成你的代码(完整
tikz
矩阵) - 第二个同时具有
nicematrix
和tikz
代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,matrix,calc,positioning}
\usepackage{nicematrix}
\tikzset{
table/.style={
matrix of math nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={rectangle,text width=3em,align=center},
text depth=1.25ex,
text height=2.5ex,
nodes in empty cells,
left delimiter=[,
right delimiter={]},
ampersand replacement=\&
}
}
\begin{document}
\[
A=
\begin{tikzpicture}[baseline,decoration=brace]
\matrix (m) [table] {
1 \& 0 \& \cdots \& 0 \& \& 1 \& 1 \& \cdots \& 1 \\
0 \& 1 \& \cdots \& 0 \& \& 0 \& 0 \& \cdots \& 0 \\
\vdots \& \vdots \& \ddots \& 0 \& \& \vdots \& \vdots \&\ddots\& \vdots \\
0 \& 0 \& \cdots \& 1 \& \& 0 \& 0 \& \cdots \& 0 \\
0 \& 0 \& \cdots \& 0 \& \& 1 \& 0 \& \cdots \& 1 \\
0 \& 0 \& \cdots \& 0 \& \& 0 \& 1 \& \cdots \& 0 \\
\vdots \& \vdots \& \ddots \& 0 \& \& \vdots \& \vdots \&\ddots\& \vdots \\
1 \& 1 \& \cdots \& 1 \& \& 0 \& 0 \& \cdots \& 1 \\
};
\node [above=.5em of m-1-1.north, anchor=south] {$a_{1n}$};
\node [above=.5em of m-1-2.north, anchor=south] {$a_{2n}$};
\node [above=.5em of m-1-3.north, anchor=south] {$\ldots$};
\node [above=.5em of m-1-4.north, anchor=south] {$a_{mn}$};
\node [above=.5em of m-1-6.north, anchor=south] {$a_{11}$};
\node [above=.5em of m-1-7.north, anchor=south] {$a_{12}$};
\node [above=.5em of m-1-8.north, anchor=south] {$\ldots$};
\node [above=.5em of m-1-9.north, anchor=south] {$a_{1n-1}$};
\draw[decorate,transform canvas={xshift=1.4em},thick] (m-1-9.north east) -- node[right=2pt] {$m$} (m-4-9.south east); % right
\draw[decorate,transform canvas={xshift=1.4em},thick] (m-5-9.north east) -- node[right=2pt] {$n$} (m-8-9.south east); % right
\draw[decorate,transform canvas={yshift=-.5em},thick] (m-8-4.south east) -- node[below=2pt] {$m$} (m-8-1.south west); % below
\draw[decorate,transform canvas={yshift=-.5em},thick] (m-8-9.south east) -- node[below=2pt] {$n-1$} (m-8-6.south west); % below
\draw [dotted] (m-1-5.north) -- (m-8-5.south);
\draw [dotted] (m-4-1.south west) -- (m-4-9.south east);
\end{tikzpicture}
\]
$A''=\begin{pNiceMatrix}[first-row,%
code-before =
{
\tikz \draw[decorate, decoration=brace,transform canvas={xshift=1.4em},thick] (row-1-|col-10) -- node[right=2pt] {$m$} (row-5-|col-10); % right
\tikz \draw[decorate, decoration=brace,transform canvas={xshift=1.4em},thick] (row-5-|col-10) -- node[right=2pt] {$n$} (row-9-|col-10); % right
\tikz \draw[decorate, decoration=brace,transform canvas={yshift=-.5em},thick] (row-9-|col-5) -- node[below=2pt] {$m$} (row-9-|col-1); % below
\tikz \draw[decorate, decoration=brace,transform canvas={yshift=-.5em},thick] (row-9-|col-10) -- node[below=2pt] {$n-1$} (row-9-|col-6); % below
}
]
a_{1n} & a_{2n} & \Cdots & a_{mn} && a_{11} & a_{12} & \Cdots & a_{1n-1}\\
1 & 0 & \Cdots & 0 & \Vdotsfor{8} & 1 & 1 & \Cdots & 1\\
0 & 1 & \Cdots & 0 & & 0 & 0 & \Cdots & 0\\
\Vdots & \Vdots & \Ddots & \Vdots & & \Vdots & \Vdots & \Ddots & \Vdots\\
0 & 0 & \Cdots & 1 & & 0 & 0 & \Cdots & 0\\
\hdottedline
0 & 0 & \Cdots & 0 & & 1 & 0 & \Cdots & 0\\
0 & 0 & \Cdots & 0 & & 0 & 1 & \Cdots & 0\\
\Vdots & \Vdots & \Ddots & \Vdots & & \Vdots & \Vdots & \Ddots & \Vdots\\
1 & 1 & \Cdots & 1 & & 0 & 0 & \Cdots & 1
\end{pNiceMatrix}$
\end{document}
结果
答案2
以下是您可以使用最新版本的操作nicematrix
。
\documentclass{article}
\usepackage{nicematrix,tikz}
\begin{document}
$A=\begin{pNiceArray} [first-row,last-col,xdots/line-style=loosely dotted] {cccc:cccc}
a_{1n} & a_{2n} & \Cdots & a_{mn} & a_{11} & a_{12} & \Cdots & a_{1n-1} \hspace*{-6pt}\\
1 & 0 & \Cdots & 0 & 1 & 1 & \Cdots & 1 & \Block{4-1}{\quad m}\\
0 & 1 & \Cdots & 0 & 0 & 0 & \Cdots & 0 \\
\Vdots & \Vdots & \Ddots & \Vdots & \Vdots & \Vdots & \Ddots & \Vdots \\
0 & 0 & \Cdots & 1 & 0 & 0 & \Cdots & 0 \\
\hdottedline
0 & 0 & \Cdots & 0 & 1 & 0 & \Cdots & 0 & \Block{4-1}{\quad n}\\
0 & 0 & \Cdots & 0 & 0 & 1 & \Cdots & 0 \\
\Vdots & \Vdots & \Ddots & \Vdots & \Vdots & \Vdots & \Ddots & \Vdots \\
1 & 1 & \Cdots & 1 & 0 & 0 & \Cdots & 1
\CodeAfter
\UnderBrace{last-1}{last-4}{m\vphantom{1}}[shorten,yshift=1.1mm]
\UnderBrace{last-5}{last-8}{n-1}[shorten,yshift=1.1mm]
\SubMatrix{.}{1-1}{4-last}{\}}[xshift=2mm]
\SubMatrix{.}{5-1}{last-last}{\}}[xshift=2mm]
\end{pNiceArray}$
\end{document}