我有两个问题:
- 如何在矩阵之间添加更多水平间距?
- 此外,有没有办法在矩阵上方添加一些文本?
我添加了一张带有所需输出的图片。
以下是获取左侧矩阵的 MWE:
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix,chains,positioning,decorations.pathreplacing,arrows}
\begin{document}
\[
\begin{matrix}
\begin{bmatrix}
\begin{tikzpicture}
\matrix [matrix of math nodes] (m)
{
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 6 & 3 & 5 & 2 & 1 & 0 \\
0 & 2 & 1 & 7 & 8 & 4 & 0 \\
0 & 1 & 8 & 4 & 1 & 7 & 0 \\
0 & 6 & 3 & 5 & 2 & 1 & 0 \\
0 & 2 & 1 & 7 & 8 & 4 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
};
\draw[color=red] (m-1-1.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- (m-1-1.north west);
\end{tikzpicture}
\end{bmatrix}\\
%\end{bmatrix}\\
\\
\begin{bmatrix}
\begin{tikzpicture}
\matrix [matrix of math nodes] (m)
{
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 3 & 1 & 0 & 2 & 0 \\
0 & 9 & 3 & 4 & 2 & 6 & 0 \\
0 & 1 & 2 & 8 & 9 & 2 & 0 \\
0 & 5 & 6 & 4 & 5 & 1 & 0 \\
0 & 7 & 5 & 3 & 3 & 7 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
};
\draw[color=green] (m-1-1.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- (m-1-1.north west);
\end{tikzpicture}
\end{bmatrix}\\
\\
\begin{bmatrix}
\begin{tikzpicture}
\matrix [matrix of math nodes] (m)
{
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 3 & 1 & 8 & 1 & 9 & 0 \\
0 & 4 & 5 & 2 & 1 & 8 & 0 \\
0 & 7 & 6 & 3 & 1 & 1 & 0 \\
0 & 7 & 4 & 8 & 2 & 5 & 0 \\
0 & 8 & 4 & 8 & 8 & 3 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
};
\draw[color=blue] (m-1-1.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- (m-1-1.north west);
\end{tikzpicture}
\end{bmatrix}
\end{matrix}
%
\begin{matrix}
\begin{bmatrix}
\begin{tikzpicture}
\matrix [matrix of math nodes] (m)
{
0 & 1 & 0 \\
0 & 1 & 1 \\
1 & 1 & 1 \\
};
\draw[color=red] (m-1-1.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- (m-1-1.north west);
\end{tikzpicture}
\end{bmatrix}\\
\\
\begin{bmatrix}
\begin{tikzpicture}
\matrix [matrix of math nodes] (m)
{
0 & 1 & 0 \\
1 & 0 & 1 \\
1 & 0 & 0 \\
};
\draw[color=green] (m-1-1.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- (m-1-1.north west);
\end{tikzpicture}
\end{bmatrix}\\
\\
\begin{bmatrix}
\begin{tikzpicture}
\matrix [matrix of math nodes] (m)
{
1 & 0 & 1 \\
1 & 1 & 0 \\
1 & 1 & 0 \\
};
\draw[color=blue] (m-1-1.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- (m-1-1.north west);
\end{tikzpicture}
\end{bmatrix}
\end{matrix}
=
\begin{matrix}
\begin{bmatrix}
\begin{tikzpicture}
\matrix [matrix of math nodes] (m)
{
1 & 1 & 1 \\
0 & 1 & 1 \\
1 & 0 & 0 \\
};
\draw[color=yellow] (m-1-1.north west) -- (m-1-1.north east) -- (m-1-1.south east) -- (m-1-1.south west) -- (m-1-1.north west);
\end{tikzpicture}
\end{bmatrix}\\
\end{matrix}
\label{eq:convex}
\]
\end{document}
答案1
您可以将矩阵放在array
环境中,这样就可以轻松地将标题放在列的顶部。至于额外的空间,您可以使用设置所需的长度arraycolsep
。
编辑:正如 egreg 在评论中所述,\arraycolsep
会影响的放置pmatrix
,因此要在矩阵之间设置额外的空间,请改用\begin{array{@{}c@{\hspace{20pt}}c@{\hspace{20pt}}c@{\hspace{20pt}}c@{}}
。
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix,chains,positioning,decorations.pathreplacing,arrows}
\setlength{\arraycolsep}{20pt}
\begin{document}
\[
\begin{array{@{}c@{\hspace{20pt}}c@{\hspace{20pt}}c@{\hspace{20pt}}c@{}}
Title 1 & Title 2 & & Title 3\\
\begin{matrix}
\begin{bmatrix}
\begin{tikzpicture}
\matrix [matrix of math nodes] (m)
{
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 6 & 3 & 5 & 2 & 1 & 0 \\
0 & 2 & 1 & 7 & 8 & 4 & 0 \\
0 & 1 & 8 & 4 & 1 & 7 & 0 \\
0 & 6 & 3 & 5 & 2 & 1 & 0 \\
0 & 2 & 1 & 7 & 8 & 4 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
};
\draw[color=red] (m-1-1.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- (m-1-1.north west);
\end{tikzpicture}
\end{bmatrix}\\
%\end{bmatrix}\\
\\
\begin{bmatrix}
\begin{tikzpicture}
\matrix [matrix of math nodes] (m)
{
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 3 & 1 & 0 & 2 & 0 \\
0 & 9 & 3 & 4 & 2 & 6 & 0 \\
0 & 1 & 2 & 8 & 9 & 2 & 0 \\
0 & 5 & 6 & 4 & 5 & 1 & 0 \\
0 & 7 & 5 & 3 & 3 & 7 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
};
\draw[color=green] (m-1-1.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- (m-1-1.north west);
\end{tikzpicture}
\end{bmatrix}\\
\\
\begin{bmatrix}
\begin{tikzpicture}
\matrix [matrix of math nodes] (m)
{
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 3 & 1 & 8 & 1 & 9 & 0 \\
0 & 4 & 5 & 2 & 1 & 8 & 0 \\
0 & 7 & 6 & 3 & 1 & 1 & 0 \\
0 & 7 & 4 & 8 & 2 & 5 & 0 \\
0 & 8 & 4 & 8 & 8 & 3 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
};
\draw[color=blue] (m-1-1.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- (m-1-1.north west);
\end{tikzpicture}
\end{bmatrix}
\end{matrix}
&
\begin{matrix}
\begin{bmatrix}
\begin{tikzpicture}
\matrix [matrix of math nodes] (m)
{
0 & 1 & 0 \\
0 & 1 & 1 \\
1 & 1 & 1 \\
};
\draw[color=red] (m-1-1.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- (m-1-1.north west);
\end{tikzpicture}
\end{bmatrix}\\
\\
\begin{bmatrix}
\begin{tikzpicture}
\matrix [matrix of math nodes] (m)
{
0 & 1 & 0 \\
1 & 0 & 1 \\
1 & 0 & 0 \\
};
\draw[color=green] (m-1-1.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- (m-1-1.north west);
\end{tikzpicture}
\end{bmatrix}\\
\\
\begin{bmatrix}
\begin{tikzpicture}
\matrix [matrix of math nodes] (m)
{
1 & 0 & 1 \\
1 & 1 & 0 \\
1 & 1 & 0 \\
};
\draw[color=blue] (m-1-1.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- (m-1-1.north west);
\end{tikzpicture}
\end{bmatrix}
\end{matrix}
& = &
\begin{matrix}
\begin{bmatrix}
\begin{tikzpicture}
\matrix [matrix of math nodes] (m)
{
1 & 1 & 1 \\
0 & 1 & 1 \\
1 & 0 & 0 \\
};
\draw[color=yellow] (m-1-1.north west) -- (m-1-1.north east) -- (m-1-1.south east) -- (m-1-1.south west) -- (m-1-1.north west);
\end{tikzpicture}
\end{bmatrix}\\
\end{matrix}
\label{eq:convex}
\end{array}
\]
\end{document}
给出: