5

I am trying to draw a simple probability tree, where the probabilites could sometimes be fraction or decimals., this means, I will have to adjust the spacing. So I tried the below code. This produces tree but label gone, and error thrown.

\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}

Output:
enter image description here

Error:
enter image description here

  • Might be useful if you also cite the error – daleif Nov 24 '18 at 14:15
  • I have added the screenshot – Parthiban Rajendran Nov 24 '18 at 14:16
6

There are actually 2 issues.

  1. style 3 args does not exist, use style n args={3}{... instead.
  2. You define for the 2nd argument xshift=#2 but add one more xshift when you are saying my edge label={above}{xshift=-2mm}{0.002}.

Working code:

\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}

enter image description here

Simpler code: pgfkeys already accept comma-separated arguments, which is illustrated in my edge label={above,xshift=-3mm}{0.002}. And instead the xshift you my just use above left or below left etc., as in 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}

enter image description here

  • Instead of above and a negative xshift you may also try above left. – user121799 Nov 24 '18 at 14:25
  • thanks marmot :) any way I could make that optional also, so I need not always give that some default value? – Parthiban Rajendran Nov 24 '18 at 14:52
  • @PaariVendhan Yes, of course, with pgfkeys. (Sorry, I was hibernating.) What do you want to make default? (Will decouple now again for one hour.) – user121799 Nov 24 '18 at 17:24
  • No, not default, just optional (so even if i do not pass anything, nothing happens foreg, what happens if i did not send xshift value - result should be if what if i did not use xshift in the style) – Parthiban Rajendran Nov 24 '18 at 17:35
  • 1
    @PaariVendhan nodes already allow for optional keys, so IMHO you only need 2 arguments, not three. I illustrated this in another example. – user121799 Nov 24 '18 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.