![将参数传递给 forestset 来绘制树时出现奇怪的错误](https://linux22.com/image/386535/%E5%B0%86%E5%8F%82%E6%95%B0%E4%BC%A0%E9%80%92%E7%BB%99%20forestset%20%E6%9D%A5%E7%BB%98%E5%88%B6%E6%A0%91%E6%97%B6%E5%87%BA%E7%8E%B0%E5%A5%87%E6%80%AA%E7%9A%84%E9%94%99%E8%AF%AF.png)
我正在尝试绘制一个简单的概率树,其中概率有时可能是分数或小数。这意味着,我必须调整间距。所以我尝试了下面的代码。这会产生树,但标签会消失,并抛出错误。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[linguistics]{forest}
\usepackage{philex}
\forestset{
my edge label/.style 3 args={
edge label={node[midway, font=\sffamily\scriptsize, #1,xshift=#2]{#3}},
},
}
\title{Problem customizing forest tree}
\author{parthi292929 }
\date{November 2018}
\begin{document}
\maketitle
\section{Introduction}
\scalebox{1.2}{
\begin{forest}
for tree={grow'=east}
[0
[Diseased, my edge label={above}{xshift=-2mm}{0.002}
[Positive
]
[Negative(FN)
]
]
[No Disease
[Positive
]
[Negative
]
]
]
]
\end{forest}
}
\end{document}
答案1
实际上有两个问题。
style 3 args
不存在,请改用style n args={3}{...
。- 您为第二个参数定义,但是在说话时
xshift=#2
再添加一个。xshift
my edge label={above}{xshift=-2mm}{0.002}
工作代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[linguistics]{forest}
\usepackage{philex}
\forestset{
my edge label/.style n args={3}{
edge label={node[midway, font=\sffamily\scriptsize, #1,xshift=#2]{#3}},
},
}
\title{Problem customizing forest tree}
\author{parthi292929 }
\date{November 2018}
\begin{document}
\maketitle
\section{Introduction}
\scalebox{1.2}{
\begin{forest}
for tree={grow'=east}
[0
[Diseased,my edge label={above}{-2mm}{0.002}
[Positive
]
[Negative(FN)
]
]
[No Disease
[Positive
]
[Negative
]
]
]
]
\end{forest}
}
\end{document}
更简单的代码:pgfkeys 已经接受逗号分隔的参数,如中所示my edge label={above,xshift=-3mm}{0.002}
。而xshift
您只需使用above left
或below left
等,如中所示my edge label={below left}{0.998}
。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[linguistics]{forest}
\usepackage{philex}
\forestset{
my edge label/.style n args={2}{
edge label={node[midway, font=\sffamily\scriptsize,#1]{#2}},
},
}
\title{Problem customizing forest tree}
\author{parthi292929 }
\date{November 2018}
\begin{document}
\maketitle
\section{Introduction}
\scalebox{1.2}{
\begin{forest}
for tree={grow'=east}
[0
[Diseased,my edge label={above,xshift=-3mm}{0.002}
[Positive
]
[Negative(FN)
]
]
[No Disease,my edge label={below left}{0.998}
[Positive
]
[Negative
]
]
]
]
\end{forest}
}
\end{document}