将参数传递给 forestset 来绘制树时出现奇怪的错误

将参数传递给 forestset 来绘制树时出现奇怪的错误

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

\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

实际上有两个问题。

  1. style 3 args不存在,请改用style n args={3}{...
  2. 您为第二个参数定义,但是在说话时xshift=#2再添加一个。xshiftmy 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 leftbelow 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}

在此处输入图片描述

相关内容