更改 TikZ 水平图中文本框的宽度

更改 TikZ 水平图中文本框的宽度

我是 Ti 的新手Z,但我需要一个父子水平图。我的问题是框的宽度是固定的,我不知道如何更改它。

通过查看类似问题的答案,我以为会改变

[grow'=right,level distance=1.25in,sibling distance=.15in, scale=0.80]

[grow'=right,level distance=1.25in,sibling distance=.15in, scale=0.80, text width=4.25in]

应该可以解决问题,但是却不行。

那么,基本上,如何改变文本框的文本宽度?

\documentclass{article}

\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees} % this is to allow the fork right path

\begin{document}
\begin{tikzpicture}[grow'=right,level distance=2.25in,sibling distance=.15in, scale=0.80]
\tikzset{edge from parent/.style= 
            {thick, draw, edge from parent fork right},
         every tree node/.style=
            {draw,minimum width=1in,text width=1in,align=center}}
\Tree 
    [. {Very long text for the parent node} 
        [.{The first child} ]
        [.{The second child with extra baggage}
                [.{A lot of text describing this second child, really a lot of text, about this much } ]
            [.{A lot of text describing this second child, really a lot of text, about this much } ]
            [.{A lot of text describing this second child, really a lot of text, about this much } ]
            [.{A lot of text describing this second child, really a lot of text, about this much} ]
        ] 
        [.{Third child will probably also have baggage} ]
        [.{But this is just an example} ]
    ]
\end{tikzpicture}
\end{document}

电流输出

答案1

您可以用任意命令替换文本,\node之后所有节点命令都会生效。例如,您可以更改倒数第二个框的宽度以实现:

在此处输入图片描述

使用代码:

\documentclass{article}

\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees} % this is to allow the fork right path

\begin{document}
\begin{tikzpicture}[grow'=right,level distance=2.25in,sibling distance=.15in, scale=0.80]
\tikzset{edge from parent/.style=
            {thick, draw, edge from parent fork right},
         every tree node/.style=
            {draw,minimum width=1in,text width=1in,align=center}}
\Tree
    [. {Very long text for the parent node}
        [.{The first child} ]
        [.{The second child with extra baggage}
                [.{A lot of text describing this second child, really a lot of text, about this much } ]
            [.{A lot of text describing this second child, really a lot of text, about this much } ]
            [.{A lot of text describing this second child, really a lot of text, about this much } ]
            [.{A lot of text describing this second child, really a lot of text, about this much} ]
        ]
        [.\node[minimum width=45mm, fill=blue!10]{Third child will probably also have baggage}; ]
        [.{But this is just an example} ]
    ]
\end{tikzpicture}
\end{document}

请注意,正如您minimum width=1in,text width=1in在图表顶部的表格规格中所设置的,该text width规格在此示例中仍设置为1in,因此保持不变。

答案2

forest

\documentclass{article}
\usepackage[edges]{forest}

\begin{document}
\begin{forest}
for tree = {
% nodes
    draw, font=\small, 
    text centered,
% tree    
    grow' = east,
    forked edge,
    l sep=8mm,
 fork sep=4mm,
%
    where level={2}{text width=12em}{text width=8em},
    where level={1}{s sep=2mm}{s sep=7mm},
            }
% diagram
[Very long text for the parent node, calign=edge midpoint
    [The first child]
    [The second child with extra baggage, calign=edge midpoint
        [{A lot of text describing this second child,
          really a lot of text, about this much}]
        [{A lot of text describing this second child,
          really a lot of text, about this much}]
        [{A lot of text describing this second child,
          really a lot of text, about this much}]
        [{A lot of text describing this second child,
          really a lot of text, about this much}]
    ]
    [Third child will probably also have baggage]
    [But this is just an example]
]
\end{forest}
\end{document}

在此处输入图片描述

相关内容