我用过这用户 cfr 的回复非常棒,编辑后我得到了一棵不错的树。但是我想更改一些小东西。我玩了一些数字,但它的代码有点超出我的理解范围。在我完成并显示以下内容后,我无法进行任何其他更改。我觉得我错过了一些东西,但我无法弄清楚。
我正在尝试复制另一本书中的一棵树,但我的树看起来不太一样。我希望第一个分割也是直的,并且我希望叶节点(有时也是非叶节点)周围没有框。我正在使用 W.Rankl 和 W. Effing 编写的《智能卡手册》第 3 版。我尝试复制的树是第 18 页和第 255 页上的树。这是我目前拥有的:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage[edges]{forest}
\forestset{
declare dimen register=gap,
gap'=10mm,
declare count register=twist,
twist'=1,
family tree too/.style={
draw,
forked edges,
for tree={
fill=gray!0,
rounded corners=1pt,
minimum width/.wrap pgfmath arg={##1}{(\textwidth-6*(gap))/3},
minimum height=4ex,
font=\sffamily,
text centered,
edge=thick,
},
where={level()<(twist)}{%
parent anchor=children,
l sep+=5pt,
}{%
draw,
folder,
grow'=0,
if={level()==(twist)}{%
before typesetting nodes={child anchor=north},
anchor=north,
edge path'={%
(!u.parent anchor) -- (.child anchor)
},
}{
l sep'+=2pt,
if level=2{
before computing xy={
l/.wrap pgfmath arg={##1}{14pt-((\textwidth-6*(gap))/6)}
},
}{}
},
},
},
}
\begin{document}
\begin{figure}[!ht]
\centering
\begin{forest}
family tree too,
[Lorem ipsum dolor sit amet con
[Lorem ips
[Lorem ipsum
[Lorem ipsum dolor sit.]
[Lorem ipsum dolor s]
]
[Lorem ipsum dolor si
[Lorem ipsum dolor s]
[Lorem ipsum dolo]
]
]
[Lorem ipsum dolor sit am
[Lorem ipsum d]
[Lorem ipsum]
[Lorem ipsum]
]
]
\end{forest}
\caption{A small tree}
\label{fig:smart_card_types}
\end{figure}
\end{document}
它看起来是这样的:
以下是我想复制的内容:
(1): Wolfgang Rankl 和 Wolfgang Effing,《智能卡手册》,第 3 版。英国西萨塞克斯郡奇切斯特;美国新泽西州霍博肯:J. Wiley,2003 年。
答案1
这是您的代码的稍微简化的版本,(我认为)它可以完成您想要的操作。
\documentclass{article}
\usepackage{tikz}
\usepackage[edges]{forest}
\begin{document}
\begin{figure}[!ht]
\centering
\begin{forest}
forked edges, folder indent=1cm,
where={level()<1}{}{folder, grow'=east},
where={level()>0}{l sep+=1cm}{},
for tree={
fork sep=4mm,
thick, edge=thick,
font=\sffamily,
if n children=0{if n=1{yshift=-5mm}{}, for parent={s sep=0mm}}{draw, minimum height=4ex, minimum width=4cm}
}
[Lorem ipsum dolor sit amet con, calign=edge midpoint, s sep=2cm, font=\bfseries\sffamily
[Lorem ips
[Lorem ipsum
[Lorem ipsum dolor sit.]
[Lorem ipsum dolor s]
]
[Lorem ipsum dolor si
[Lorem ipsum dolor s]
[Lorem ipsum dolo]
]
]
[Lorem ipsum dolor sit am
[Lorem ipsum d]
[Lorem ipsum]
[Lorem ipsum]
]
]
\end{forest}
\caption{A small tree}
\label{fig:smart_card_types}
\end{figure}
\end{document}