使 Tikz 节点看起来像文本行

使 Tikz 节点看起来像文本行

我想创建一个包含多个文本节点的图形,并使它们看起来像真正的多行文本。

本质上我需要两样东西:

  1. 找出要使用的适当节点距离(我通过转储 \the\baselineskip 获得此信息)。
  2. 安排所有节点使用该距离。

如果每个节点只有一行,我就可以完成这项工作:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,trees,positioning,arrows, fit}
\begin{document}
    \begin{tikzpicture}[]
            \begin{scope}[
                    node distance   = 18.0pt,
            ]
            \node[rectangle, font=\huge] (Title) {Title};
            \node[inner sep=0, font=\Large, align=left] (start) [below=of Title] {Hello};
            \node[inner sep=0, font=\Large, align=left] (mid) [below=of start.west,anchor=west] {Hi};
            \node[inner sep=0,font=\Large, align=left] (end) [below=of mid.west,anchor=west] {Bye};
            \end{scope}
    \end{tikzpicture}
\end{document}

但是,如果节点有多条线,那么就会有重叠:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,trees,positioning,arrows, fit}
\begin{document}
    \begin{tikzpicture}[]
            \begin{scope}[
                    node distance   = 18.0pt,
            ]
            \node[rectangle, font=\huge] (Title) {Title};
            \node[inner sep=0, font=\Large, align=left] (start) [below=of Title] {Hello};
            \node[inner sep=0, font=\Large, align=left] (mid) [below=of start.west,anchor=west] {Hi};
            \node[inner sep=0,font=\Large, align=left] (end) [below=of mid.west,anchor=west] {Bye \\ Bye \\ Bye};
            \end{scope}
    \end{tikzpicture}
\end{document}

显然,我想避免将所有文本拆分为单行节点,并且我不想手动使用 yshift 来修复距离。有什么想法吗?

提前致谢!

答案1

如果将节点相对于适当的锚点定位,则不会发生重叠。

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
    \begin{tikzpicture}[]
            \begin{scope}[
                    node distance   = 6pt,
            ]
            \node[rectangle, font=\huge,anchor=south west] (Title) {Title};
            \node[inner sep=0, font=\Large, align=left] (start) [below=of
            Title.south west,anchor=north west] {Hello};
            \node[inner sep=0, font=\Large, align=left] (mid) [below=of
            start.south west,anchor=north west] {Hi};
            \node[inner sep=0,font=\Large, align=left] (end) 
            [below=of mid.south west,anchor=north west] {Bye \\ Bye \\ Bye};
            \end{scope}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

但是,我不确定我是否理解了其目的。您是否恰好在寻找shapes.multipartmatrix

答案2

您可以连接链中的节点:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains, positioning}

\begin{document}
    \begin{tikzpicture}[
    start chain = going below left,
    node distance = 6pt and 0pt
                        ]
        \node[font=\huge,anchor=south west] (Title) {Title};
        \begin{scope}[every node/.append style = {
                font=\Large, align=left, inner sep=0pt,
                on chain, anchor=north west}
                      ]
        \node[below=of Title.south west] {Hello};
        \node {Hi};
        \node {Bye \\ Bye \\ Bye};
        \end{scope}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容