分类树不适合该页面

分类树不适合该页面

我曾尝试绘制下面的树,但是它不适合一页纸而且超出了页面范围。

\documentclass[10pt]{article}
\usepackage{forest}
\usetikzlibrary{shadows}

\begin{document}
    \tikzset{
        my node/.style={
            draw=gray,
            inner color=gray!5,
            outer color=gray!10,
            thick,
            minimum width=1cm,
%           rounded corners=3,
            text height=1.5ex,
            text depth=0ex,
            font=\sffamily,
            drop shadow,
        }
    }
    \begin{forest}
        for tree={%
            my node,
            l sep+=5pt,
            grow'=east,
            edge={gray, thick},
            parent anchor=east,
            child anchor=west,
            if n children=0{tier=last}{},
            edge path={
                \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(10pt,0) |- (.child anchor)\forestoption{edge label};
            },
            if={isodd(n_children())}{
                for children={
                    if={equal(n,(n_children("!u")+1)/2)}{calign with current}{}
                }
            }{}
        }
        [Nwdefd  efdewf
        [Exact 
        [Tewewf fewfew Methods[feweff][fewfmqwd][Quad-Trees][Ohyyyhyrttge][Cregregrgregregerg][regrgfregregreggreg][regrefwfwefefTrees]][Filtereferfr anrfrfd Verefr[Fast Nreewewewfew Neiuwefewr][Principle Axdwfeis Searewfrefrch Tewffrees][Orrefrefrfrthogonal Sewferfearch Trrefrefreees][Hyyrhyhtyperplane Bounfwewfewewds+]]]
        [Apewfewproxewfewewewimate Nearewfewfest Neigewewfewhbour Seefewewewarch
        [Hashewfewfing Baewfewfewsed[Locaeewfewlity Sensiewfewfetive Haewfewfshing][Leaewfweffewrning to Hewfewfewfewash]][Paewfewewfrtition Bawefewqwewsed[Baewfwwfelancewewed Box][Baewfeweewewewlanced Aewfwspeewfewct Ratewfio]][Grewfewfaph Based[Deewfewlewfewfeaewfewunay graphs][ navigaewfewewfble small worewfwefld gewffewraeffewph]]]]
        ]
    \end{forest}
\end{document}

在此处输入图片描述

答案1

如果节点内确实需要那么多文本,则可能应该使用较小的字体。然后,我建议您删除该text depth选项并添加一个text width选项以启用换行。一旦使用正确的英语单词(或另一种现有人类语言的单词),连字符就会起作用,然后文本将正确适合框。

\documentclass[10pt]{article}
\usepackage{forest}
\usetikzlibrary{shadows}

\begin{document}
    \tikzset{
        my node/.style={
            draw=gray,
            inner color=gray!5,
            outer color=gray!10,
            thick,
            minimum width=1cm,
%           rounded corners=3,
            text height=1.5ex,
%           text depth=0ex,
            text width=2cm,
            font=\sffamily\scriptsize,
            drop shadow,
        }
    }
    \begin{forest}
        for tree={%
            my node,
            l sep+=5pt,
            grow'=east,
            edge={gray, thick},
            parent anchor=east,
            child anchor=west,
            if n children=0{tier=last}{},
            edge path={
                \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(10pt,0) |- (.child anchor)\forestoption{edge label};
            },
            if={isodd(n_children())}{
                for children={
                    if={equal(n,(n_children("!u")+1)/2)}{calign with current}{}
                }
            }{}
        }
        [Nwdefd  efdewf
        [Exact 
        [Tewewf fewfew Methods[feweff][fewfmqwd][Quad-Trees][Ohyyyhyrttge][Cregregrgregregerg][regrgfregregreggreg][regrefwfwefefTrees]][Filtereferfr anrfrfd Verefr[Fast Nreewewewfew Neiuwefewr][Principle Axdwfeis Searewfrefrch Tewffrees][Orrefrefrfrthogonal Sewferfearch Trrefrefreees][Hyyrhyhtyperplane Bounfwewfewewds+]]]
        [Apewfewproxewfewewewimate Nearewfewfest Neigewewfewhbour Seefewewewarch
        [Hashewfewfing Baewfewfewsed[Locaeewfewlity Sensiewfewfetive Haewfewfshing][Leaewfweffewrning to Hewfewfewfewash]][Paewfewewfrtition Bawefewqwewsed[Baewfwwfelancewewed Box][Baewfeweewewewlanced Aewfwspeewfewct Ratewfio]][Grewfewfaph Based[Deewfewlewfewfeaewfewunay graphs][ navigaewfewewfble small worewfwefld gewffewraeffewph]]]]
        ]
    \end{forest}
\end{document}

在此处输入图片描述

相关内容