以 tikz 森林图为中心?

以 tikz 森林图为中心?

我有一个几乎完成的 tikz/forest 图表,但还有一些问题。1a/1b:标题和图表未对齐。我希望它们居中,因​​此标题需要向右移动(解决方案 1a)或图表需要向左移动(解决方案 1b)。最好的解决方法是什么?2:我希望图表中的第一列不出现,或者是垂直的。这可能吗?3:如何改变每列的最小宽度?(级别?)我当前设置的方式使所有级别的宽度相同,但每个级别的文本量不同,因此效率不高。

请参阅以下屏幕截图和代码:

在此处输入图片描述

\documentclass{article}

\usepackage{forest}
\useforestlibrary{edges}
\usetikzlibrary {decorations.pathreplacing, calligraphy}
\tikzset{mybrace/.style={decorate, decoration={calligraphic brace, amplitude=2mm}, ultra thick, transform canvas={xshift=1mm}}}

\begin{document}

\begin{figure}
\centering
\caption{Experimental Conditions and the Number of Observations}
\medskip

\newcommand*{\equal}{=}

% tier/.pgfmath=level()
\begin{forest}
for tree={grow'=east, minimum width=28mm}
[
    [Versions, for tree={no edge, draw}[1p[1i[2p]]]
    ]
    [V1, no edge, for tree={forked edge, draw}
        [wwwww[rrr[wwwww (N{\equal}xx), name=A1][llllll (N{\equal}xx)]][uuuuu[wwwww (N{\equal}xx)][llllll (N{\equal}xx)]]]
        [llllll[rrr[wwwww (N{\equal}xx)][llllll (N{\equal}xx)]][uuuuu[wwwww (N{\equal}xx)][llllll (N{\equal}xx), name=B1]]]
    ]
    [V2, no edge, for tree={forked edge, draw}
        [wwwww[rrr[wwwww (N{\equal}xx), name=A2][llllll (N{\equal}xx)]][uuuuu[wwwww (N{\equal}xx)][llllll (N{\equal}xx)]]]
        [llllll[rrr[wwwww (N{\equal}xx)][llllll (N{\equal}xx)]][uuuuu[wwwww (N{\equal}xx)][llllll (N{\equal}xx), name=B2]]]
    ]
%    [V2, no edge, for tree={forked edge, draw}
%        [wwwww[rrr[A, name=A2][B]][uuuuu[A][B]]]
%        [llllll[rrr[A][B]][uuuuu[A][B, name=B2]]]
%    ]
]
\draw[mybrace] (A1.north east)--node[right=2mm]{V1}(B1.south east);
\draw[mybrace] (A2.north east)--node[right=2mm]{V2}(B2.south east);
\end{forest}
\end{figure}
\end{document}

答案1

由于您有一个不可见的 0 级,因此森林向右移动,但它仍然占用空间。设置l sep=-5mm0 级以补偿括号和括号标签并删除minimum width。然后将 更改minimum width为除最后一个以外的其他级别。

最后,for descendantsV1V2节点上使用,这样它们就不会被绘制。

在此处输入图片描述

\documentclass{article}

\usepackage{forest}
\useforestlibrary{edges}
\usetikzlibrary {decorations.pathreplacing, calligraphy}
\tikzset{mybrace/.style={decorate, decoration={calligraphic brace, amplitude=2mm}, ultra thick, transform canvas={xshift=1mm}}}

\begin{document}

\begin{figure}
\centering
\caption{Experimental Conditions and the Number of Observations}
\medskip

\newcommand*{\equal}{=}

% tier/.pgfmath=level()
\begin{forest}
for tree={grow'=east, if level=0{l sep=-5mm}{if n children=0{minimum width=28mm}{minimum width=15mm}}}
[
    [Versions, for tree={no edge, draw}[1p[1i[2p]]]
    ]
    [V1, no edge, for descendants={forked edge, draw}
        [wwwww[rrr[wwwww (N{\equal}xx), name=A1][llllll (N{\equal}xx)]][uuuuu[wwwww (N{\equal}xx)][llllll (N{\equal}xx)]]]
        [llllll[rrr[wwwww (N{\equal}xx)][llllll (N{\equal}xx)]][uuuuu[wwwww (N{\equal}xx)][llllll (N{\equal}xx), name=B1]]]
    ]
    [V2, no edge, for descendants={forked edge, draw}
        [wwwww[rrr[wwwww (N{\equal}xx), name=A2][llllll (N{\equal}xx)]][uuuuu[wwwww (N{\equal}xx)][llllll (N{\equal}xx)]]]
        [llllll[rrr[wwwww (N{\equal}xx)][llllll (N{\equal}xx)]][uuuuu[wwwww (N{\equal}xx)][llllll (N{\equal}xx), name=B2]]]
    ]
%    [V2, no edge, for tree={forked edge, draw}
%        [wwwww[rrr[A, name=A2][B]][uuuuu[A][B]]]
%        [llllll[rrr[A][B]][uuuuu[A][B, name=B2]]]
%    ]
]
\draw[mybrace] (A1.north east)--node[right=2mm]{V1}(B1.south east);
\draw[mybrace] (A2.north east)--node[right=2mm]{V2}(B2.south east);
\end{forest}
\end{figure}
\end{document}

相关内容