
Estoy intentando automatizar el diseño de ciertos árboles que deseo usar repetitivamente, pero parece que no puedo hacer que el \forestset
comando funcione en el preámbulo. En los códigos siguientes, supongo que la parte comentada del archivo en el documento principal debería ser innecesaria, una vez que esta información se haya pasado al preámbulo. Pero tal como está actualmente, la información del preámbulo no modifica el diseño predeterminado del árbol resultante. (Tenga en cuenta que esto tampoco produce un error de compilación).
\documentclass[10pt,oneside,pdftex,dvipsnames,a4paper]{article}
\usepackage{forest}
\forestset{
sn edges/.style={
for tree={
grow'=0,
l=0pt, inner sep=0.075cm, s sep=0.1mm,
child anchor=west,parent anchor=south,
anchor=west,calign=first,
edge path={
\noexpand\path [draw, \forestoption{edge}]
(!u.south west) +(7.5pt,0) |- node{} (.child anchor)\forestoption{edge label};
},
before typesetting nodes={
if n=1
{insert before={[,phantom]}}
{}
},
fit=band,
before computing xy={l=15pt},
}
}
}
%-------------------------------------------------------------
\begin{document}
\begin{forest}
% for tree={
% grow'=0,
% l=0pt, inner sep=0.075cm, s sep=0.1mm,
% child anchor=west,parent anchor=south,
% anchor=west,calign=first,
% edge path={
% \noexpand\path [draw, \forestoption{edge}]
% (!u.south west) +(7.5pt,0) |- node{} (.child anchor)\forestoption{edge label};
% },
% before typesetting nodes={
% if n=1
% {insert before={[,phantom]}}
% {}
% },
% fit=band,
% before computing xy={l=15pt},
% }
[$B$
[$B_{1}$]
[$B_{2}$
[$A$
[$A_{1}$,tikz={\node [draw,inner sep=0.5pt,fit to=tree]{};}]
[$A_{2}$
[$D$]
[$E$]
]
[$A_{3}$
]
]
]
]
\end{forest}
\end{document}
Respuesta1
Usted define el estilo sn edges
en el preámbulo, pero no dice que quiere que su árbol lo use. Para hacer esto, debes proporcionar el nombre del estilo como clave en tu árbol.
MWE:
\documentclass{article}
\usepackage{forest}
\forestset{
sn edges/.style={
for tree={
grow'=0,
l=0pt, inner sep=0.075cm, s sep=0.1mm,
child anchor=west,parent anchor=south,
anchor=west,calign=first,
edge path={
\noexpand\path [draw, \forestoption{edge}]
(!u.south west) +(7.5pt,0) |- node{} (.child anchor)\forestoption{edge label};
},
before typesetting nodes={
if n=1
{insert before={[,phantom]}}
{}
},
fit=band,
before computing xy={l=15pt},
}
}
}
%-------------------------------------------------------------
\begin{document}
\begin{forest}
sn edges,
[$B$
[$B_{1}$]
[$B_{2}$
[$A$
[$A_{1}$,tikz={\node [draw,inner sep=0.5pt,fit to=tree]{};}]
[$A_{2}$
[$D$]
[$E$]
]
[$A_{3}$
]
]
]
]
\end{forest}
\end{document}
Resultado:
Una alternativa no es crear un nuevo estilo sino aplicar el estilo dado automáticamente a todos los árboles usando la default preamble
tecla \forestset
. En este caso, no es necesario proporcionar una clave de estilo para árboles individuales.
\documentclass{article}
\usepackage{forest}
\forestset{
default preamble={
for tree={
grow'=0,
l=0pt, inner sep=0.075cm, s sep=0.1mm,
child anchor=west,parent anchor=south,
anchor=west,calign=first,
edge path={
\noexpand\path [draw, \forestoption{edge}]
(!u.south west) +(7.5pt,0) |- node{} (.child anchor)\forestoption{edge label};
},
before typesetting nodes={
if n=1
{insert before={[,phantom]}}
{}
},
fit=band,
before computing xy={l=15pt},
}
}
}
%-------------------------------------------------------------
\begin{document}
\begin{forest}
[$B$
[$B_{1}$]
[$B_{2}$
[$A$
[$A_{1}$,tikz={\node [draw,inner sep=0.5pt,fit to=tree]{};}]
[$A_{2}$
[$D$]
[$E$]
]
[$A_{3}$
]
]
]
]
\end{forest}
\end{document}
Respuesta2
Debe \forestset
definir el estilo qué nombre se considera en forest
el entorno. Ver MWE a continuación:
\documentclass[a4paper]{article}
\usepackage{forest}
\forestset{my tree/.style = {% NEW
for tree={
inner sep=0.075cm,
l sep=1mm,% CHANGED AND CORRECTED
s sep=1mm,% changed
grow'=0,
child anchor=west,parent anchor=south,
anchor=west,calign=first,
edge path={
\noexpand\path [draw, \forestoption{edge}]
(!u.south west) +(7.5pt,0) |- node{} (.child anchor)\forestoption{edge label};
},
before typesetting nodes={
if n=1
{insert before={[,phantom]}}
{}
},
fit=band,
before computing xy={l=15pt},
}% end of for tree
}% end of my tree style
}% end of forestset
%-------------------------------------------------------------
\begin{document}
\begin{forest} my tree
[$B$
[$B_{1}$]
[$B_{2}$
[$A$
[$A_{1}$,tikz={\node [draw,inner sep=0.5pt,fit to=tree]{};}]
[$A_{2}$
[$D$]
[$E$]
]
[$A_{3}$
]
]
]
]
\end{forest}
\end{document}