将两张 Tikz 图片放入对齐环境中

将两张 Tikz 图片放入对齐环境中

我想将两张 tikz 图片像等式一样放在一起。以下是我目前所得到的:

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\usetikzlibrary{matrix}
\usepackage[x11names]{xcolor}

\begin{document}

Conversely, we can think of an $n \times p$ matrix $\mathbf{A}$ as two different groups of vectors. First, we can think of the \textit{rows} of $\mathbf{A}$ as a collection of row vectors, that is, the matrix is a collection of $n$ vectors all with order $p$. We can also think of the \textit{columns} of $\mathbf{A}$ as a collection of column vectors; that is, the matrix is a collection of $p$ different vectors, all with order $n$. 

\begin{figure}[ht]
\centering
\begin{tikzpicture}
        \matrix [matrix of math nodes,left delimiter=(,right delimiter=)] (m)
        {
            a_{1,1} & \cdots & a_{1,p} \\[-1.5ex]               
            \vdots & \ddots & \vdots \\               
            a_{n,1} & \cdots & a_{n,p} \\           
        };  

        \draw[color=orange, fill = orange, fill opacity = 0.25, rounded corners] (m-1-1.north west) -- (m-1-3.north east) -- (m-1-3.south east) -- (m-1-1.south west) -- cycle;

        \draw[color=orange, fill = orange, fill opacity = 0.25, rounded corners] (m-3-1.north west) -- (m-3-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- cycle;

        \draw [decorate, decoration = {brace, amplitude = 5pt, mirror, raise = 3mm}, black] (m-3-1.south west) -- (m-3-3.south east) node[midway, yshift = -2.75em, align = center]{A collection of\\row vectors};
\end{tikzpicture}
\begin{tikzpicture}
        \matrix [matrix of math nodes,left delimiter=(,right delimiter=)] (m)
        {
            a_{1,1} & \cdots & a_{1,p} \\[-1.5ex]               
            \vdots & \ddots & \vdots \\               
            a_{n,1} & \cdots & a_{n,p} \\           
        };  

        \draw[color=SteelBlue3, fill = SteelBlue3, fill opacity = 0.25, rounded corners] (m-1-1.north west) -- (m-1-1.north east) -- (m-3-1.south east) -- (m-3-1.south west) -- cycle;

        \draw[color=SteelBlue3, fill = SteelBlue3, fill opacity = 0.25, rounded corners] (m-1-3.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-3.south west) -- cycle;

        \draw [decorate, decoration = {brace, amplitude = 5pt, mirror, raise = 3mm}, black] (m-3-1.south west) -- (m-3-3.south east) node[midway, yshift = -2.75em, align = center]{A collection of\\column vectors};
\end{tikzpicture}
\end{figure}

\end{document}

这是我的输出:

在此处输入图片描述

我希望它看起来像一个使用align环境的方程,这样 A = 第一个矩阵 = 第二个矩阵。有什么办法可以做到这一点吗?

答案1

当然可以这样做。您只需添加一个适当的ampersand replacement(因为align查找),并且您的中不能有空行,环境内的任何内容中也&不能有空行。我还选择了可能适合此示例的基线,但您也可以使用例如将这些矩阵垂直居中。tikzpicturealign\vcenter{\hbox{...}}

\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing}

\begin{document}

Conversely, we can think of an $n \times p$ matrix $\mathbf{A}$ as two different groups of vectors. First, we can think of the \textit{rows} of $\mathbf{A}$ as a collection of row vectors, that is, the matrix is a collection of $n$ vectors all with order $p$. We can also think of the \textit{columns} of $\mathbf{A}$ as a collection of column vectors; that is, the matrix is a collection of $p$ different vectors, all with order $n$. 
\begin{align}
 A &=
\begin{tikzpicture}[baseline=(m-2-1.base)]
        \matrix [matrix of math nodes,left delimiter=(,right delimiter=),
        ampersand replacement=\&] (m)
        {
            a_{1,1} \& \cdots \& a_{1,p} \\[-1.5ex]               
            \vdots \& \ddots \& \vdots \\               
            a_{n,1} \& \cdots \& a_{n,p} \\           
        };  
        \draw[color=orange, fill = orange, fill opacity = 0.25, rounded corners] (m-1-1.north west) -- (m-1-3.north east) -- (m-1-3.south east) -- (m-1-1.south west) -- cycle;
        \draw[color=orange, fill = orange, fill opacity = 0.25, rounded corners] (m-3-1.north west) -- (m-3-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- cycle;
        \draw [decorate, decoration = {brace, amplitude = 5pt, mirror, raise = 3mm}, black] (m-3-1.south west) -- (m-3-3.south east) node[midway, yshift = -2.75em, align = center]{A collection of\\row vectors};
\end{tikzpicture}
=
\begin{tikzpicture}[baseline=(m-2-1.base)]
        \matrix [matrix of math nodes,left delimiter=(,right delimiter=),
        ampersand replacement=\&] (m)
        {
            a_{1,1} \& \cdots \& a_{1,p} \\[-1.5ex]               
            \vdots \& \ddots \& \vdots \\               
            a_{n,1} \& \cdots \& a_{n,p} \\           
        };  
        \draw[color=SteelBlue3, fill = SteelBlue3, fill opacity = 0.25, rounded corners] (m-1-1.north west) -- (m-1-1.north east) -- (m-3-1.south east) -- (m-3-1.south west) -- cycle;
        \draw[color=SteelBlue3, fill = SteelBlue3, fill opacity = 0.25, rounded corners] (m-1-3.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-3.south west) -- cycle;
        \draw [decorate, decoration = {brace, amplitude = 5pt, mirror, raise = 3mm}, black] (m-3-1.south west) -- (m-3-3.south east) node[midway, yshift = -2.75em, align = center]{A collection of\\column vectors};
\end{tikzpicture}
\end{align}
\end{document}

在此处输入图片描述

我个人会在上面绘制圆角矩形,background layer并稍微减少矩阵下文本行之间的距离,但这当然只是一个品味问题。

\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing,backgrounds}

\begin{document}

Conversely, we can think of an $n \times p$ matrix $\mathbf{A}$ as two different groups of vectors. First, we can think of the \textit{rows} of $\mathbf{A}$ as a collection of row vectors, that is, the matrix is a collection of $n$ vectors all with order $p$. We can also think of the \textit{columns} of $\mathbf{A}$ as a collection of column vectors; that is, the matrix is a collection of $p$ different vectors, all with order $n$. 
\begin{align}
 \mathbf{A} &=
\begin{tikzpicture}[baseline=(m-2-1.base)]
        \matrix [matrix of math nodes,left delimiter=(,right delimiter=),
        ampersand replacement=\&] (m)
        {
            a_{1,1} \& \cdots \& a_{1,p} \\[-1.5ex]               
            \vdots \& \ddots \& \vdots \\               
            a_{n,1} \& \cdots \& a_{n,p} \\           
        };  
        \begin{scope}[on background layer]
        \draw[color=orange, fill = orange, fill opacity = 0.25, rounded corners] (m-1-1.north west) -- (m-1-3.north east) -- (m-1-3.south east) -- (m-1-1.south west) -- cycle;
        \draw[color=orange, fill = orange, fill opacity = 0.25, rounded corners] (m-3-1.north west) -- (m-3-3.north east) -- (m-3-3.south east) -- (m-3-1.south west) -- cycle;
        \end{scope}
        \draw [decorate, decoration = {brace, amplitude = 5pt, mirror, raise =
        3mm}, black] (m-3-1.south west) -- (m-3-3.south east)
        node[midway, yshift = -2.75em, align = center]{A collection
        of\\[-1ex]row vectors};
\end{tikzpicture}
=
\begin{tikzpicture}[baseline=(m-2-1.base)]
        \matrix [matrix of math nodes,left delimiter=(,right delimiter=),
        ampersand replacement=\&] (m)
        {
            a_{1,1} \& \cdots \& a_{1,p} \\[-1.5ex]               
            \vdots \& \ddots \& \vdots \\               
            a_{n,1} \& \cdots \& a_{n,p} \\           
        };  
        \begin{scope}[on background layer]
        \draw[color=SteelBlue3, fill = SteelBlue3, fill opacity = 0.25, rounded corners] (m-1-1.north west) -- (m-1-1.north east) -- (m-3-1.south east) -- (m-3-1.south west) -- cycle;
        \draw[color=SteelBlue3, fill = SteelBlue3, fill opacity = 0.25, rounded corners] (m-1-3.north west) -- (m-1-3.north east) -- (m-3-3.south east) -- (m-3-3.south west) -- cycle;
        \end{scope}
        \draw [decorate, decoration = {brace, amplitude = 5pt, mirror, raise =
        3mm}, black] (m-3-1.south west) -- (m-3-3.south east)
        node[midway, yshift = -2.75em, align = center]{A collection
        of\\[-1ex]column vectors};
\end{tikzpicture}
\end{align}
\end{document}

在此处输入图片描述

相关内容