Latex学习笔记 (Ex2) 使用LaTeX画规则的树形图

树型

使用 LaTeX \LaTeX LATEX也可以进行树型图的绘制,如以下效果。在这里插入图片描述
源代码

\documentclass[11pt]{minimal}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\usetikzlibrary{trees}
\begin{document}
	\begin{tikzpicture}
	[thick,scale=1, every node/.style={scale=2}]
	\node {root}
	child {node {1}
		child {node {2}
			child {node {3}}
		}
		child [missing] {}
		child {node {3}
			child {node {2}}
		}
	}	
	child [missing] {}	
	child [missing] {}
	child [missing] {}	
	child [missing] {}	
	child { node {2}
		child {node {1}
			child {node {3}}
		}
		child [missing] {}
		child {node {3}
			child {node {1}}
		}
	}	
	child [missing] {}	
	child [missing] {}
	child [missing] {}	
	child [missing] {}	
	child { node {3}
		child {node {1}
			child {node {2}}
		}
		child [missing] {}
		child {node {2}
			child {node {1}}
		}
	};
	\end{tikzpicture}
\end{document}
 

扩展

为了实现更多的功能,搜索以后发现一个不错的资源[1],可以很方便的画各种树形图,为了做一个全排列的计算,找到了[2]. 根据少量调整,得到以下目标图片。
在这里插入图片描述

以下为 LaTeX \LaTeX LATEX 源代码。

% Author: Frantisek Burian
\documentclass{minimal}
\usepackage{tikz}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>
\begin{comment}
:Title: Filesystem tree
:Tags: Trees; Styles
:Author: Frantisek Burian
:Slug: filesystem-tree
\end{comment}
\usetikzlibrary{trees}
\begin{document}
	\tikzstyle{every node}=[draw=black,thick,anchor=west]
	\tikzstyle{selected}=[draw=red,fill=red!30]
	\tikzstyle{optional}=[dashed,fill=gray!50]
	\begin{tikzpicture}[
	grow via three points={one child at (0.5,-0.7) and two children at (0.5,-0.7) and (0.5,-1.4)},
	edge from parent path={(\tikzparentnode.south) |- (\tikzchildnode.west)}]
	\node {[1,2,3]-[]}
	child { node [selected] {i=0 move to: $\rightarrow$ [2,3]-[1]}
		child { node {[3]-[1,2]}
			child { node {[]-[1,2,3]}}
		}
		child [missing] {}	
		child { node {[2]-[1,3]}
			child {node {[] - [1,3,2]}}
		}
		child [missing] {}	
	}		
	child [missing] {}	
	child [missing] {}	
	child [missing] {}		
	child [missing] {}	
	child { node [selected] {i=0  move back: $\rightarrow$ [1,2,3]-[]}}	
	child { node {i=1 $\rightarrow$ [1,3]-[2]}}				
	child { node {i=2 $\rightarrow$ [1,2]-[3]}};
	\end{tikzpicture}
\end{document}
  • 4
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值