使用森林包实现两种不同线条风格的家谱

使用森林包实现两种不同线条风格的家谱

我正在尝试使用 forest 包以类似文件夹的方式绘制家谱。我希望用虚线标记一些孩子,因为他们不是这个人的后代,而是他/她孩子的(同父异母)兄弟姐妹。

家谱示例: 在此处输入图片描述

以及用于创建它的代码:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{palatino}
\usepackage{forest}
\begin{document}
\forestset{
  my tier/.style={% align all nodes on a given level
    tier/.wrap pgfmath arg={level##1}{level()},
  },
}
\begin{forest}
  for tree={
    grow'=0,
    child anchor=west,
    parent anchor=south,
    anchor=west,
    calign=first,
    s sep+=-5pt,
    inner sep=2.5pt,
    edge path={
      \noexpand\path [draw, \forestoption{edge}]
      (!u.south west) +(7.5pt,0) |- (.child anchor)\forestoption{edge label};
    },
    before typesetting nodes={
      if n=1{
        insert before={[, phantom, my tier]},
      }{},
    },
    my tier,
    fit=band,
    before computing xy={% change the value of l to alter the distance between levels
      l=30pt,
    },
  }
[Grandma+Steve. Steve later remarried with Betty
    [Child of Grandma+Steve
        [Grandchild]
        [Grandchild]
    ]
    [Child of Grandma+Steve
        [Grandchild of Grandma+Steve]
        [Half brother/sister]
    ]
    [Child of Steve+Betty]
]
    \end{forest}
\end{document}

我想从 Steve+Betty 的孩子到 Steve 的第二个孩子画一条虚线。如果我画,[draw, dashed, \forestoption{edge}]所有线都会变成虚线。

有没有一种简单的方法可以让某些子节点采用虚线样式?对于 Steve+Betty 的子节点,线条样式应该是实线。

我希望问题能够被清楚地表达出来。

答案1

您可以使用edge键更改所需子项的默认边缘样式。一个小例子:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{palatino}
\usepackage{forest}
\begin{document}
\forestset{
  my tier/.style={% align all nodes on a given level
    tier/.wrap pgfmath arg={level##1}{level()},
  },
}
\begin{forest}
  for tree={
    grow'=0,
    child anchor=west,
    parent anchor=south,
    anchor=west,
    calign=first,
    s sep+=-5pt,
    inner sep=2.5pt,
    edge path={
      \noexpand\path [draw, \forestoption{edge}]
      (!u.south west) +(7.5pt,0) |- (.child anchor)\forestoption{edge label};
    },
    before typesetting nodes={
      if n=1{
        insert before={[, phantom, my tier]},
      }{},
    },
    my tier,
    fit=band,
    before computing xy={% change the value of l to alter the distance between levels
      l=30pt,
    },
  }
[Grandma+Steve. Steve later remarried with Betty
    [Child of Grandma+Steve
        [Grandchild]
        [Grandchild]
    ]
    [Child of Grandma+Steve,edge={densely dashed}
        [Grandchild of Grandma+Steve]
        [Half brother/sister,edge={densely dashed}]
    ]
    [Child of Steve+Betty]
]
    \end{forest}
\end{document}

输出:

在此处输入图片描述

答案2

这非常类似于Gonzalo Medina 的回答semi-related但为了方便起见,提供了一种样式:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{palatino}
\usepackage{forest}
\begin{document}
\forestset{
  my tier/.style={% align all nodes on a given level
    tier/.wrap pgfmath arg={level##1}{level()},
  },
  semi-related/.style={%
    edge={densely dashed}
  }
}
\begin{forest}
  for tree={
    grow'=0,
    child anchor=west,
    parent anchor=south,
    anchor=west,
    calign=first,
    s sep+=-5pt,
    inner sep=2.5pt,
    edge path={
      \noexpand\path [draw, \forestoption{edge}]
      (!u.south west) +(7.5pt,0) |- (.child anchor)\forestoption{edge label};
    },
    before typesetting nodes={
      if n=1{
        insert before={[, phantom, my tier]},
      }{},
    },
    my tier,
    fit=band,
    before computing xy={% change the value of l to alter the distance between levels
      l=30pt,
    },
  }
[Grandma+Steve. Steve later remarried with Betty
    [Child of Grandma+Steve
        [Grandchild]
        [Grandchild]
    ]
    [Child of Grandma+Steve
        [Grandchild of Grandma+Steve]
        [Half brother/sister, semi-related]
    ]
    [Child of Steve+Betty, semi-related]
]
    \end{forest}
\end{document}

相关和半相关

相关内容