我正在尝试绘制一个简单的概率树,其中概率有时可能是分数或小数。这意味着,我必须调整间距。所以我尝试了下面的代码。这会产生树,但标签会消失,并抛出错误。
\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}