如何绘制由一条线链接的多行标题?

如何绘制由一条线链接的多行标题?

我想绘制与一条线相连的多行标题。我发现该行可能会覆盖第二行。

基础图形示例如下图右侧所示(取自https://en.wikipedia.org/wiki/Introduction_to_Algorithms第二版,第223页):

在此处输入图片描述


我的代码:(它会产生错误但可以编译)

\documentclass[tikz, margin=3.14mm]{standalone}
\usepackage{siunitx}
\usepackage{tikzpeople}
\usetikzlibrary{positioning,calc,arrows.meta,arrows,matrix}
\usetikzlibrary{decorations.pathreplacing}

\tikzset{
    mymat/.style={
      matrix of math nodes,
      minimum width=1cm,
      minimum height=0.5cm,
      text height=2.5ex,
      text depth=0.75ex,
      text width=3.25ex,
      align=center,
      row sep=-\pgflinewidth,
      outer sep=0pt,
      inner sep=0pt
    },
    mymat3/.style={
      matrix of math nodes,
      minimum width=0.5cm,
      minimum height=0.5cm,
      text height=2.5ex,
      text depth=0.75ex,
      text width=3.25ex,
      align=center,
      row sep=-\pgflinewidth,
      outer sep=0pt,
      inner sep=0pt
      }
    }
\begin{document}

  \begin{figure}
    \centering

    \begin{tikzpicture}
      \matrix[mymat,anchor=south west,style={nodes=draw}]
      at (5*\x+0.3,-3.6)
      (mat1)
      {
        400\\
        100\\
      };

      \draw (mat1-1-1.north west) --++ (0,0.8);
      \draw (mat1-1-1.north east) --++ (0,0.8);

      \matrix[mymat3,right=25mm of mat1-1-1.east,anchor=east,style={nodes={draw,fill=gray!30}}]
      (mat2)
      {
        1 & 2 & \dots\\
      };

      \matrix[mymat3,below=0.5 mm of mat2,style={nodes={draw,fill=gray!30}}]
      (mat5)
      {
        1 & 2 & \dots\\
      };

      \path[->, -Latex]
      (mat1-2-1.east) edge[] node [left] {} (mat5-1-1.west);
      \path[->, -Latex]
      (mat1-1-1.east) edge[] node [left] {} (mat2-1-1.west);

      \foreach \i [count=\l from 0] in {2,...,1} \node[left= 0.1mm of mat1-\i-1] {\l};
      \draw (mat2-1-1.north) --++ (0,0.5) node[align=center] {\tiny available\\\tiny life};
      \draw (mat2-1-2.north) --++ (0,0.5) node[align=center] {\tiny core\\\tiny number};
    \end{tikzpicture}
    \caption{M1}\label{fig:M1}
  \end{figure}
\end{document}

输出:

在此处输入图片描述

在这里,我已将draw (mat2-1-1.north) --++ (0,0.5) node[align=center] {\tiny available\\\tiny life};标题与一行链接起来,但该行链接到第一个句子,它会覆盖新行后的文本(life以及number示例中的字符串)。而且行与行之间有一个间隙,我无法删除。

可以是所需的图片,也可以是任何不会与标题冲突的图片:

在此处输入图片描述

相关答案:

答案1

这里和那里都需要改进。你仍然需要学习一些 TiZ 基础知识可生成直接代码。您已走在正确的道路上 ;) 希望对您有所帮助。

带标题的节点矩阵

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{siunitx}
\usepackage{tikzpeople}
\usetikzlibrary{positioning,calc,arrows.meta,arrows,matrix}
\usetikzlibrary{decorations.pathreplacing}

\tikzset{
    mymat/.style={
      matrix of math nodes,
      minimum width=1cm,
      minimum height=0.5cm,
      text height=2.5ex,
      text depth=0.75ex,
      text width=3.25ex,
      align=center,
      row sep=-\pgflinewidth,
      outer sep=0pt,
      inner sep=0pt
    },
    mymat3/.style={
      matrix of math nodes,
      minimum width=0.5cm,
      minimum height=0.5cm,
      text height=2.5ex,
      text depth=0.75ex,
      text width=3.25ex,
      align=center,
      row sep=-\pgflinewidth,
      outer sep=0pt,
      inner sep=0pt
      }
    }
\begin{document}

  \begin{figure}
    \centering

    \begin{tikzpicture}
      \matrix[mymat,anchor=south west,style={nodes=draw}]
      (mat1) at (0.3,-3.6)
        {
        400\\
        100\\
      };

      \draw (mat1-1-1.north west) --++ (0,0.8);
      \draw (mat1-1-1.north east) --++ (0,0.8);

      \matrix[mymat3,right=8mm of mat1-2-1.south east,anchor=south west,style={nodes={draw,fill=gray!30}}]
      (mat2)
      {
        1 & 2 & \dots\\
        1 & 2 & \dots\\
      };


      \draw[-Latex]
      (mat1-1-1.east) -- (mat2-1-1.west);
      \draw[-Latex]
      (mat1-2-1.east) -- (mat2-2-1.west);

      \foreach \i [count=\l from 0] in {2,...,1} \node[left= 0.1mm of mat1-\i-1] {\l};
      
      \tikzset{
              lblnode/.style={
                text width=1cm,
                align=center,
                anchor=south,
                inner sep=1pt,
                execute at begin node=\setlength{\baselineskip}{3pt}
                }
               }
      \draw (mat2-1-1.north) --++ (-0.25,0.5) node[lblnode] {\tiny available life};
      \draw (mat2-1-2.north) --++ (0.25,0.5) node[lblnode] {\tiny core number};
    \end{tikzpicture}
    \caption{M1}\label{fig:M1}
  \end{figure}
\end{document}

编辑

根据 OP 关于行和列分隔的问题,这里有一些如何修改它们的例子。

1. 没有间隙,没有大胆的线

row sep=-\pgflinewidth,
column sep=-\pgflinewidth,

没有间隙,没有粗线

2. 分隔行

row sep=2pt,
column sep=-\pgflinewidth,

分隔行

3. 分隔列

row sep=-\pgflinewidth,
column sep=2pt,

分隔列

相关内容