TeX - LaTeX Asked by Student NL on June 12, 2021
I am trying to display a classification tree on papers in my work with the forest package for LaTeX. So far, I have the following code:
begin{forest}
for tree={grow=0, s sep=0pt,
edge= thick,
anchor=base west,
font=strutfootnotesizesffamily},
%
[,phantom % Paranormal root (BOO!)
%
[2E-VRP % Real branch
[One,tier=b,
[Yes, tier=c]
[No, tier=c]
]
[Two,tier=b,
[Yes, tier=c]
[No, tier=c,
[{ex1 ex2 ex3}, tier=d]]
]
]
%
[T1,for tree={color=gray,no edge}
[T2, tier=b % Ethereal branch
[T3, tier=c,
[T4, tier=d]]]]
%
] % Closing poltergeist
%
end{forest}
resulting in this figure:
How can I get ex1, ex2, and ex3 below each other, that is, on separate lines?
You need to add align=left
to for tree
options and then write ex1 ex2 ex3
. With some small further simplifications your MWE can be:
Edit:
Considering your wish from comment below:
documentclass[border=3.141592mm]{standalone}
usepackage{forest}
tikzset{
LBL/.style = {font=footnotesizesffamily, text=gray, above=5mm}
}
begin{document}
begin{forest}
for tree={
align=left,
font=footnotesizesffamily,
anchor=west,
% tree style
grow=0,
edge= thick,
l sep=4mm,
s sep=4mm,
},
[2E-VRP, name=l1
[One,
[Yes]
[No]
]
[Two, name=l2
[Yes]
[No, name=l3
[ex1 ex2 ex3, name=l4]
]
]
]
path (l1 |- l4) node[LBL] {T1}
(l2 |- l4) node[LBL] {T2}
(l3 |- l4) node[LBL] {T3}
(l4) node[LBL] {T4};
end{forest}
end{document}
Addendum:
In the case, that you like to have a mirrored diagram, then you need to replace grow=0˙ with ˙grow'=0
and move nodes name accordingly (that level label will stay at top of the diagram):
documentclass[border=3.141592mm]{standalone}
usepackage{forest}
tikzset{
LBL/.style = {font=footnotesizesffamily, text=gray, above=5mm}
}
begin{document}
begin{forest}
for tree={
align=left,
font=footnotesizesffamily,
anchor=west,
% tree style
grow'=0,
edge= thick,
l sep=4mm,
s sep=4mm,
},
[2E-VRP, name=l1
[One, name=l2
[Yes, name=l3]
[No]
]
[Two
[Yes]
[No
[ex1 ex2 ex3, name=l4]
]
]
]
path (l1 |- l3) node[LBL] {T1}
(l2 |- l3) node[LBL] {T2}
(l3) node[LBL] {T3}
(l4 |- l3) node[LBL] {T4};
end{forest}
end{document}
Correct answer by Zarko on June 12, 2021
You could add line breaks and add an alignment using [{ex1 ex2 ex3}, tier=d, align=left]
. But I guess, this would require some additional vertical shift.
A cleaner approach would probably be to add ex1, ex2 and ex3 as children of the parent node, remove the edges of ex1 and e3 and shift them a bit closer together:
documentclass{article}
usepackage{forest}
begin{document}
begin{forest}
for tree={grow=0, s sep=0pt,
edge= thick,
anchor=base west,
font=strutfootnotesizesffamily},
%
[,phantom % Paranormal root (BOO!)
%
[2E-VRP % Real branch
[One,tier=b,
[Yes, tier=c]
[No, tier=c]
]
[Two,tier=b,
[Yes, tier=c]
[No, tier=c, s sep=-10pt
[ex3, tier=d, no edge ]
[ex2, tier=d ]
[ex1, tier=d, no edge ] ]
]
]
%
[T1, for tree={color=gray, no edge}
[T2, tier=b % Ethereal branch
[T3, tier=c,
[T4, tier=d]]]]
%
] % Closing poltergeist
%
end{forest}
end{document}
Answered by Jasper Habicht on June 12, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP