使用 Forest 包(或其他方式)更改框图中树框的对齐方式

使用 Forest 包(或其他方式)更改框图中树框的对齐方式

我需要绘制一个树状图来进行分类。从中获取提示这个问题,我得出了以下 MWE

\documentclass{book}
\usepackage[tmargin=2in, bmargin=2in, lmargin=1.5in, rmargin=1.5in]{geometry}
\usepackage{showframe}
\usepackage[edges]{forest}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{varioref}
\usepackage{cleveref}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
    \begin{enumerate}
        \item \label{usual metric on R}
        \item \label{usual metric on C}
        \item \label{usual metric on R2}
        \item \label{5}
        \item \label{6}
        \item \label{16}
        \item \label{17}
        \item \label{C_int}
        \item \label{C_sup}
        \item \label{norm}
        \item \label{extended R}
        \item \label{extended C}
        \item \label{discrete}
        \item \label{d/(1+d)}
        \item \label{product metric}
    \end{enumerate}
    \begin{figure}[h!]
        \centering
        \begin{forest}
            for tree={draw,
                where level=1{minimum height=8ex,anchor=north}{},
                align=center,
                %           font=\sffamily,
                edge+={thick, -{Stealth[]}},
                l sep'+=10pt,
                fork sep'=10pt,
            },
            forked edges,
            if level=0{
                inner xsep=0pt,
                tikz={\draw [thick] (.children first) -- (.children last);}
            }{},
            [
            \qquad Examples of metric spaces in this subsection \qquad
            [
            \Cref{usual metric on R,usual metric on C,usual metric on R2,5,6,16,17,C_int,C_sup,norm}:\\
            Normed Linear Spaces
            [
            \Cref{usual metric on R,usual metric on C,usual metric on R2,5,6}:\\
            Finite dimensional\\ vector spaces
            [\Cref{5,6}:\\ $ p $ metric and\\ \emph{sup} metric on $ \mathbb{R}^{n} $]
            [\Cref{usual metric on R,usual metric on C,usual metric on R2}:\\ usual metrics on \\ $ \mathbb{R} $\text{,} $ \mathbb{C} $ and $ \mathbb{R}^{2} $]
            ]
            [
            \Cref{16,17}:\\ Sequence spaces
            ]
            [
            \Cref{C_int,C_sup}:\\ Spaces of continuous \\ functions
            ]
            ]
            [
            \Cref{extended R,extended C}:\\ Extended set of real\\ and complex numbers
            ]
            [
            \Cref{discrete}:\\ Discrete metric
            ]
            [
            \Cref{d/(1+d),product metric}:\\ Derived metrics
            ]
            ]
        \end{forest}
        \caption{Examples of metric spaces in this subsection}
    \end{figure}
\end{document}

我想要的是让图表适合边距。为此,我想将第三和第四级的框左对齐。像这样:

在此处输入图片描述

我如何实现这个目标?

编辑

为了添加更多替代方案来实现我的目标,请考虑以下选项:

  1. 解决方案不必forest仅使用环境。任何其他提供所需输出的方式也受到欢迎。

  2. 为了更简单,以下输出也对我有用:

在此处输入图片描述

请帮忙。

答案1

这更像是一个扩展的评论,而不是真正的答案。我试图通过 来控制节点text width,但失败了。几乎可以肯定我做了一些愚蠢的事情。为了以防万一 真的有问题text width,这里有一个可以安装等效样式并运行的东西。

\documentclass{book}
\usepackage[tmargin=2in, bmargin=2in, lmargin=1.5in, rmargin=1.5in]{geometry}
\usepackage{showframe}
\usepackage[edges]{forest}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
%\usepackage{varioref}
\usepackage{cleveref}
\usetikzlibrary{arrows.meta}
\begin{document}
    \begin{enumerate}
        \item \label{usual metric on R}
        \item \label{usual metric on C}
        \item \label{usual metric on R2}
        \item \label{5}
        \item \label{6}
        \item \label{16}
        \item \label{17}
        \item \label{C_int}
        \item \label{C_sup}
        \item \label{norm}
        \item \label{extended R}
        \item \label{extended C}
        \item \label{discrete}
        \item \label{d/(1+d)}
        \item \label{product metric}
    \end{enumerate}
\fbox{\begin{minipage}{5em}\centering
\Cref{usual metric on R,usual metric on C,usual metric on R2,5,6,16,17,C_int,C_sup,norm}:\\
Normed Linear Spaces
\end{minipage}}    
    
\begin{figure}[h!]
        \centering
        \begin{forest}
            forked edges,
            for tree={draw,l sep'+=10pt,minimum height=8ex,anchor=north,
                where level=1{anchor=north,l sep+=1.5em}{},
                where level=2{fork sep=4.2em,calign=first}{fork sep=10pt},    
                where level=0{}{execute at begin node={\begin{minipage}{6em}\centering},
                execute at end node={\end{minipage}}},
                %           font=\sffamily,
                edge+={thick, -{Stealth[]}},                                
            },
            [Examples of metric spaces in this subsection,text width=21em
            [%
            \Cref{usual metric on R,usual metric on C,usual metric on R2,5,6,16,17,C_int,C_sup,norm}:\\
            Normed Linear Spaces
            [%
            \Cref{usual metric on R,usual metric on C,usual metric on R2,5,6}:\\
            Finite dimensional\\ vector spaces
            [\Cref{5,6}:\\ $ p $ metric and\\ \emph{sup} metric on $ \mathbb{R}^{n} $]
            [\Cref{usual metric on R,usual metric on C,usual metric on R2}:\\ usual metrics on \\ $ \mathbb{R} $\text{,} $ \mathbb{C} $ and $ \mathbb{R}^{2} $]
            ]
            [%
            \Cref{16,17}:\\ Sequence spaces
            ]
            [%
            \Cref{C_int,C_sup}:\\ Spaces of continuous \\ functions
            ]
            ]
            [%
            \Cref{extended R,extended C}:\\ Extended set of real\\ and complex numbers
            ]
            [%
            \Cref{discrete}:\\ Discrete metric
            ]
            [%
            \Cref{d/(1+d),product metric}:\\ Derived metrics
            ]
            ]
        \end{forest}
        \caption{Examples of metric spaces in this subsection.}
    \end{figure}
\end{document}

在此处输入图片描述

相关内容