将行距应用于 Tikz 中的数学节点矩阵

将行距应用于 Tikz 中的数学节点矩阵

我想使用 Tikz 制作一个数学节点矩阵。矩阵中的一些条目非常长,我想引入行距以将它们与以下输入对齐在同一行。但是,当我尝试这样做时,输入会从编译的文档中完全消失。

有什么办法可以做到这一点,还是我需要使用普通节点并手动强制数学模式?

梅威瑟:

\documentclass{article}
\usepackage{float}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{calc,fit,trees,positioning,arrows.meta,chains,shapes.geometric,
    decorations.pathreplacing,decorations.pathmorphing,shapes,
    matrix,shapes.symbols}

\begin{document}



\tikzset{
    mystyle/.style={column sep=0.25em, row sep=0.1em, minimum size=1cm, text width=2cm, align=center, anchor=center},
}

\begin{figure}[H]
\begin{tikzpicture}[>=latex]
\matrix (A) [matrix of math nodes,%
             nodes = {mystyle},%
             left delimiter  = {[},%
             right delimiter = {]}]
{%
{\Gamma \theta and more math mode \\ but this time on two lines \Kappa} & more input & 0 & 0 &  \ldots & 0 \\
Another line & more input & 0 & 0 &  \ldots & 0\\
};
\end{tikzpicture}
\begin{tikzpicture}
\matrix (T) [matrix of math nodes,%
             nodes = {mystyle},%
             left delimiter  = {[},%
             right delimiter = {]}] 
{% 
Test \\
Test 2 \\
};

\node [mystyle, right= 0.4cm of T] {= Answer};
\end{tikzpicture}
\caption{I want to include linespacing in this tikz figure in the first column.}
\end{figure}

\end{document}

答案1

您可以在节点中放置gathered或环境。multlined

在此处输入图片描述

\documentclass{article}
\usepackage{float}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{calc,fit,trees,positioning,arrows.meta,chains,shapes.geometric,
    decorations.pathreplacing,decorations.pathmorphing,shapes,
    matrix,shapes.symbols}

\begin{document}


\tikzset{
    mystyle/.style={column sep=0.25em, row sep=0.1em, minimum size=1cm, text width=2cm, align=center, anchor=center},
}

\begin{figure}[H]
\begin{tikzpicture}[>=latex]
\matrix (A) [matrix of math nodes,%
             nodes = {mystyle},%
             left delimiter  = {[},%
             right delimiter = {]}]
{%
\begin{gathered}
  \Gamma \theta \\
  \epsilon\delta
 \end{gathered} & \begin{multlined} a \\ b \end{multlined} & 0 & 0 &  \ldots & 0 \\
Another line & more input & 0 & 0 &  \ldots & 0\\
};
\end{tikzpicture}
\begin{tikzpicture}
\matrix (T) [matrix of math nodes,%
             nodes = {mystyle},%
             left delimiter  = {[},%
             right delimiter = {]}] 
{% 
Test \\
Test 2 \\
};

\node [mystyle, right= 0.4cm of T] {= Answer};
\end{tikzpicture}
\caption{I want to include linespacing in this tikz figure in the first column.}
\end{figure}

\end{document}

相关内容