我想制作一个组织结构图,每个节点都有图片、姓名、mobile.nr 和电子邮件...我尝试使用 tikz 树位失败了。如何在节点中添加图片?有人能帮我吗?请
答案1
有一种可能性是:
\documentclass[border=6pt]{standalone}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees}
\usepackage[
colorlinks=true,
urlcolor=cyan!70!black
]{hyperref}
\tikzset{
basic/.style={
draw,
text width=6.5cm,
minimum height=40pt,
font=\sffamily,
inner sep=0pt,
},
}
\newcommand\mynode[7][]{
\node[#1] (#2)
{\parbox{20pt}{%
\includegraphics[height=40pt,width=20pt]{#3}}%
\parbox{10pt}{\mbox{}}%
\parbox{\dimexpr6.5cm-30pt\relax}{#4\\[.4ex]#5\\\footnotesize\texttt{#6}\ \url{#7}}%
};
}
\begin{document}
\begin{tikzpicture}[
level 1/.style={sibling distance=80mm},
edge from parent/.style={->,draw},
>=latex,
every node/.style={basic}
]
% root
\mynode{root}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
% The first level
\mynode[below left= of root]{c1}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\mynode[below = of root]{c2}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\mynode[below right= of root]{c3}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\begin{scope}[node distance=-\pgflinewidth and 1cm]
\mynode[below = 10pt of c1, xshift=15pt]{c11}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\mynode[below = of c11]{c12}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\mynode[below = of c12]{c13}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\mynode[below = 10pt of c2, xshift=15pt]{c21}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\mynode[below = of c21]{c22}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\mynode[below = of c22]{c23}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\mynode[below = of c23]{c24}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\mynode[below = 10pt of c3, xshift=15pt]{c31}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\mynode[below = of c31]{c32}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\mynode[below = of c32]{c33}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\mynode[below = of c33]{c34}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\mynode[below = of c34]{c35}{flor}{No Body}{All and nothing}{00-123456}{[email protected]}
\end{scope}
% lines from root to level 1
\draw (root.south) -- ++(0,-13pt) -| (c1.north);
\draw (root.south) -- ++(0,-13pt) -| coordinate[pos=0.05] (aux) (c3.north);
\draw (aux) -- (aux|-c2.north);
% lines from each level 1 node to every one of its "children"
\foreach \value in {1,2,3}
\draw[->] ([xshift=6pt]c1.south west) |- (c1\value.west);
\foreach \value in {1,...,4}
\draw[->] ([xshift=6pt]c2.south west) |- (c2\value.west);
\foreach \value in {1,...,5}
\draw[->] ([xshift=6pt]c3.south west) |- (c3\value.west);
\end{tikzpicture}
\end{document}
该命令\mynode
有一个可选参数,用于将选项传递给所使用的内部节点,还有六个强制参数(如果每个节点的图像相同,则可以简化定义):
\mynode[<options for the node>]{<name>}{<image file>}{<text line1>}{<text line2>}{<telephone number>}{<url>}