如何在流程图中写入矩阵?

如何在流程图中写入矩阵?

我是 LaTeX 新手,我想在流程图中写入矩阵。我该怎么做?

矩阵应该进入空节点并与一些文本连接:

在此处输入图片描述

当前将矩阵存储在变量中的方法不起作用:

\documentclass...
...
\usepackage{tikz}
\usepackage{amsmath}
\newcommand{\mat}{\[
\begin{bmatrix}
    1 & 2 & 3 & 4 & 5 \\
    3 & 4 & 5 & 6 & 7
  \end{bmatrix}
\]}
...
{\centering
\begin{tikzpicture}[node distance=2cm]
...
\node (pro3) [process, below of=pro2] {\mat};


...
\par}
...
\end...

或者,我可以尝试将第二行字符沿制表符排列,但这会很混乱。

请问您能帮忙吗?

答案1

您存储矩阵的方法确实有效,但您正在使用\[ ... \]环境,因此您需要准备节点来排版此类内容。例如,可以通过添加一些来完成text width。当然,如果您只想添加矩阵,\[ ... \]可能不是最好的选择,相反,因为由 Steven B. Segletes 提及,您可能只需要使用$...$,在这种情况下,您不需要像这样的密钥text width

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newcommand{\mat}{\[
\begin{bmatrix}
    1 & 2 & 3 & 4 & 5 \\
    3 & 4 & 5 & 6 & 7
  \end{bmatrix}
\]}
\newcommand{\othermat}{$\begin{bmatrix}
    1 & 2 & 3 & 4 & 5 \\
    3 & 4 & 5 & 6 & 7
  \end{bmatrix}$}
\begin{document}
\centering
\begin{tikzpicture}[node distance=2cm,process/.style={draw,fill=orange}]
\node (pro2){test};
\node (pro3) [process, below of=pro2,text width=3cm] {\mat};
\end{tikzpicture}\quad
\begin{tikzpicture}[node distance=2cm,process/.style={draw,fill=orange}]
\node (pro2){test};
\node (pro3) [process, below of=pro2] {\othermat};
\end{tikzpicture}
\end{document}

\documentclass{article}

\usepackage{tikz}
\usepackage{amsmath}
\newcommand{\mat}{\[
\begin{bmatrix}
    1 & 2 & 3 & 4 & 5 \\
    3 & 4 & 5 & 6 & 7
  \end{bmatrix}
\]}
\begin{document}
\centering
\begin{tikzpicture}[node distance=2cm]

\node (pro3) [%process, below of=pro2
text width=3cm] {\mat};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容