如何在 Latex 中制作地图(键/值)?

如何在 Latex 中制作地图(键/值)?

希望在 LaTeX 中创建一种带有键/值的 Map 的图像,如下所示:

在此处输入图片描述

我尝试使用 TikZ 制作图像并得到以下脚本:

\begin{tikzpicture}

\tikzset{
  block/.style = {draw, minimum width=1.0cm, minimum height=0.7cm, node distance=3cm},
  down/.style={yshift=-4em}
}

\node[block] (4) at (0,0) {4};
\node[block,right of=4] (3) {3};
\node[block,right of=3] (7) {7};

\node[block] (A1) at ([down] 4) {A1};
\node[block] (A3) at ([down] 3) {A3};
\node[block] (A4) at ([down] 7) {A4};

\draw[->] (4) -- (3);
\draw[->] (3) -- (7);

\draw[->] (4) -- (A1);
\draw[->] (3) -- (A3);
\draw[->] (7) -- (A4);

\end{tikzpicture}

但是我如何修改下部节点(A1,A3,A4)以使它们看起来像表格?

答案1

您还可以使用tikz matrix

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}

\begin{document}
    \begin{figure}
        \centering
        \begin{tikzpicture}
        \tikzset{
            block/.style = {draw, minimum width=1.0cm, minimum height=0.7cm, rounded corners, node distance=3cm},
            mymatrix/.style = {matrix of nodes, nodes={draw, text width=4em, minimum height=4ex, inner xsep=6pt}, 
                row sep=-\pgflinewidth, column sep=-\pgflinewidth, inner sep=0pt},
        }
        \node[block] (4) at (0,0) {4};
        \node[block,right= of 4] (3) {3};
        \node[block,right= of 3] (7) {7};
        \matrix[mymatrix, below= of 4] (A1) {%
            order 5\\
            main 4\\
            net 3\\
        };
        \matrix[mymatrix, below= of 3] (A3) {%
            order 7 \\ 
            main 4 \\ 
            net 1 \\
        };
        \matrix[mymatrix, below= of 7] (A4) {%
            order 8  \\ 
            main 9  \\ 
            net 7  \\
        };
        \draw[->] (4) -- (3);
        \draw[->] (3) -- (7);
        \draw[->] (4) -- (A1);
        \draw[->] (3) -- (A3);
        \draw[->] (7) -- (A4);
        \end{tikzpicture}
        \caption{Maps\label{fig:M1}}
    \end{figure}
\end{document}

在此处输入图片描述

答案2

最后,我使用 TikZ 解决了这个问题,附加了脚本,谢谢大家。

\begin{figure}
\centering
\begin{tikzpicture}

\tikzstyle{block} = [draw, line width=0.25mm, minimum width=1.0cm, minimum height=0.7cm, node distance=3cm]
\tikzstyle{down} = [yshift=-4em]


\node[block, rounded corners] (4) at (0,0) {4};
\node[block,right of=4, rounded corners] (3) {3};
\node[block,right of=3, rounded corners] (7) {7};

\node[block] (A1) at ([down] 4) 
{ 
\begin{tabular}{ l   }
    order 5  \\ \hline
    main 4  \\ \hline
    net 3  \\
  \end{tabular} 
};
\node[block] (A3) at ([down] 3) 
{
\begin{tabular}{ l   }
    order 7  \\ \hline
    main 4  \\ \hline
    net 1 \\
  \end{tabular} 
};
\node[block] (A4) at ([down] 7) 
{
    \begin{tabular}{ l   }
    order 8  \\ \hline
    main 9  \\ \hline
    net 7  \\
  \end{tabular} 
};

\draw[->] (4) -- (3);
\draw[->] (3) -- (7);

\draw[->] (4) -- (A1);
\draw[->] (3) -- (A3);
\draw[->] (7) -- (A4);

\end{tikzpicture}
\caption{Maps} \label{fig:M1}
\end{figure}

在此处输入图片描述

答案3

整个画面仅用一句话就可以定义matrix

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}

\begin{document}
    \begin{figure}
        \centering
        \begin{tikzpicture}
        \tikzset{
            block/.style = {draw, text width=2em, minimum height=0.7cm, rounded corners, outer sep=0pt, anchor=center, align=center},
            register/.style = {draw, text width=4em, minimum height=4ex, inner xsep=6pt, outer sep=0pt, anchor=center}, 
            map/.style={matrix of nodes, nodes=register, row sep=-\pgflinewidth, column sep=1cm, row 1/.style={nodes=block}},
        }
        \matrix[map] (A) {
            4 & 3 & 7 \\[1cm]
         order 5 & order 7 & order 8\\
         main 4 & main 4 & main 9\\
         net 3 & net 1& net 7\\
        };
          \foreach \i in {1,2,3}
                \draw[->] (A-1-\i) -- (A-2-\i);
        \draw[->] (A-1-1) -- (A-1-2);
        \draw[->] (A-1-2) -- (A-1-3);
        \end{tikzpicture}
        \caption{Maps\label{fig:M1}}
    \end{figure}
\end{document}

在此处输入图片描述

相关内容