使横向 Tikz 图形适合页面

使横向 Tikz 图形适合页面

我在 tikz 中制作了以下大型树,我正尝试将其作为论文的一部分进行展示。不用说,这棵树太大了,无法适应纵向模式,因此我一直试图让它适应横向模式,但无济于事。我尝试过调整节点距离和级别距离......但同样无济于事。有人能帮助我并推荐呈现这棵树的最佳方式,使其保持完全可见吗?

\documentclass{book}
\usepackage{amsmath,amssymb,amstext,amsthm}
\usepackage[pdftex]{graphicx}
\usepackage[parfill]{parskip}
\usepackage{tikz}
\usepackage{fancybox}
\usepackage{lscape}
\usepackage{rotating}
\begin{document}
\begin{sidewaysfigure}[ht]
\centering
\begin{tikzpicture}[scale=0.5, level 1/.style={sibling distance=300mm}, level 2/.style={sibling distance=150mm}, level 3/.style={sibling distance=75mm},  level 4/.style={sibling distance=40mm, level distance=35mm}]
\node[circle, draw]{$b\smash{_5}$}
    child{node[circle, draw]{$b\smash{_1}$}
        child{node[circle, draw]{$b\smash{_2}$}
            child{node[circle, draw]{$b\smash{_4}$}
                child{node[rectangle, draw]{$b\smash{_1} \gets 1$}}
                child{node[rectangle, draw]{$b\smash{_2} \gets 1$}} 
            }
            child{node[circle, draw]{$b\smash{_4}$}
                child{node[rectangle, draw]{$b\smash{_1} \gets 1$}}
                child{node[rectangle, draw]{$b\smash{_4} \gets 0$}} 
            }   
        }
        child{node[circle, draw]{$b\smash{_3}$}
            child{node[circle, draw]{$b\smash{_2}$}
                child{node[rectangle, draw]{$b\smash{_1} \gets 0$}}
                child{node[rectangle, draw]{$b\smash{_1} \gets 0$}} 
            }
            child{node[circle, draw]{$b\smash{_4}$}
                child{node[rectangle, draw]{$b\smash{_4} \gets 1$}}
                child{node[rectangle, draw]{$b\smash{_3} \gets 0$}} 
            }   
        }
    }
    child{node[circle, draw]{$b\smash{_1}$}
        child{node[circle, draw]{$b\smash{_2}$}
            child{node[circle, draw]{$b\smash{_4}$}
                child{node[rectangle, draw]{$b\smash{_1} \gets 1$}}
                child{node[rectangle, draw]{$b\smash{_2} \gets 1$}} 
            }
            child{node[circle, draw]{$b\smash{_4}$}
                child{node[rectangle, draw]{$b\smash{_1} \gets 1$}}
                child{node[rectangle, draw]{$b\smash{_4} \gets 0$}} 
            }   
        }
        child{node[circle, draw]{$b\smash{_3}$}
            child{node[circle, draw]{$b\smash{_2}$}
                child{node[rectangle, draw]{$b\smash{_1} \gets 0$}}
                child{node[rectangle, draw]{$b\smash{_1} \gets 0$}} 
            }
            child{node[circle, draw]{$b\smash{_4}$}
                child{node[rectangle, draw]{$b\smash{_4} \gets 1$}}
                child{node[rectangle, draw]{$b\smash{_3} \gets 0$}} 
            }   
        }
    }
;
\end{tikzpicture}
\caption{A Decision Tree}
\label{datfvo}
\end{sidewaysfigure}
\end{document}

答案1

您可以通过改变来恢复很多宽度level distance(只要它不会冒犯您的对称感)。

\documentclass{book}
\usepackage{amsmath,amssymb,amstext,amsthm}
\usepackage[pdftex]{graphicx}
\usepackage[parfill]{parskip}
\usepackage{tikz}
\usepackage{fancybox}
\usepackage{pdflscape}
\usepackage{rotating}
\begin{document}
\begin{landscape}
\begin{figure}
\centering
\begin{tikzpicture}[scale=0.5, level 1/.style={sibling distance=180mm}, level 2/.style={sibling distance=90mm}, level 3/.style={sibling distance=45mm},  level 4/.style={sibling distance=20mm, level distance=25mm}]
\node[circle, draw]{$b\smash{_5}$}
    child{node[circle, draw]{$b\smash{_1}$}
        child{node[circle, draw]{$b\smash{_2}$}
            child{node[circle, draw]{$b\smash{_4}$}
                child{node[rectangle, draw]{$b\smash{_1} \gets 1$}}
                child[level distance=40mm]{node[rectangle, draw]{$b\smash{_2} \gets 1$}} 
            }
            child{node[circle, draw]{$b\smash{_4}$}
                child{node[rectangle, draw]{$b\smash{_1} \gets 1$}}
                child[level distance=40mm]{node[rectangle, draw]{$b\smash{_4} \gets 0$}} 
            }   
        }
        child{node[circle, draw]{$b\smash{_3}$}
            child{node[circle, draw]{$b\smash{_2}$}
                child{node[rectangle, draw]{$b\smash{_1} \gets 0$}}
                child[level distance=40mm]{node[rectangle, draw]{$b\smash{_1} \gets 0$}} 
            }
            child{node[circle, draw]{$b\smash{_4}$}
                child{node[rectangle, draw]{$b\smash{_4} \gets 1$}}
                child[level distance=40mm]{node[rectangle, draw]{$b\smash{_3} \gets 0$}} 
            }   
        }
    }
    child{node[circle, draw]{$b\smash{_1}$}
        child{node[circle, draw]{$b\smash{_2}$}
            child{node[circle, draw]{$b\smash{_4}$}
                child{node[rectangle, draw]{$b\smash{_1} \gets 1$}}
                child[level distance=40mm]{node[rectangle, draw]{$b\smash{_2} \gets 1$}} 
            }
            child{node[circle, draw]{$b\smash{_4}$}
                child{node[rectangle, draw]{$b\smash{_1} \gets 1$}}
                child[level distance=40mm]{node[rectangle, draw]{$b\smash{_4} \gets 0$}} 
            }   
        }
        child{node[circle, draw]{$b\smash{_3}$}
            child{node[circle, draw]{$b\smash{_2}$}
                child{node[rectangle, draw]{$b\smash{_1} \gets 0$}}
                child[level distance=40mm]{node[rectangle, draw]{$b\smash{_1} \gets 0$}} 
            }
            child{node[circle, draw]{$b\smash{_4}$}
                child{node[rectangle, draw]{$b\smash{_4} \gets 1$}}
                child[level distance=40mm]{node[rectangle, draw]{$b\smash{_3} \gets 0$}} 
            }   
        }
    }
;
\end{tikzpicture}
\caption{A Decision Tree}
\label{datfvo}
\end{figure}
\end{landscape}
\end{document}

我也曾经pdflscape在生成的 pdf 中旋转页面。

适合的决策树

答案2

您也可以扩展单个节点。

\begin{tikzpicture}[scale=0.3, every node/.style={scale=0.7}]

答案3

我只需改变页面的几何形状以确保没有页眉/页脚。

您还可以更改比例,0.4 似乎没问题?

如果它对你来说太小,那么就直接实现,xscale=0.4而不是整个scale=.5

相关内容