编辑

编辑

我目前正在使用 forest-usepackage 来构建家谱。我想在森林节点内实现一个表。只要我没有达到 100 次失败标记,代码就会被编译,一切看起来都很好。

我的问题:如何解决我的支架失败问题?

下面我得到了一个最小化的例子。

\documentclass[margin=1cm]{standalone}
%
\usepackage[latin1]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[edges,linguistics]{forest}
\usepackage{textcomp}
%
\begin{document}
%
\begin{forest}
  for tree=
    {
     draw,
     minimum height=3cm,
     minimum width=3cm,
     l sep+=2cm,
     edge path={\noexpand\path[\forestoption{edge}] (\forestOve{\forestove{@parent}}{name}.parent anchor) -- +(0,-1cm)-| (\forestove{name}.child anchor)\forestoption{edge label};}
    }
    [{\begin{tabular}{ll}{Stephanus & \\ ... & ... \\ abc & äöü}\end{tabular}}
       [Christina]
       [Maria]
       [Stephanus]
     ]
\end{forest}
%
\end{document}

仅显示以下消息:

Error line 25 !Missing }inserted.<inserted text>}\end{forest}

Error line 25 !Missing {inserted.<inserted text>{\end{forest}

"I've put in what seems to be necessary to fix
the current column of the current alignment.
Try to go on, since this might almost work."

答案1

如果您将表中删除花括号(导致您遇到问题的原因是内部花括号),那么您的问题就会消失:

在此处输入图片描述

\documentclass[margin=3mm]{standalone}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[edges,linguistics]{forest}
%\usepackage{textcomp}

\begin{document}
%
\begin{forest}
  for tree = {draw,
     minimum height = 2cm, % <-- changed
      minimum width = 3cm,
               font = \linespread{.9}\selectfont, %< -- added for less vertical space between lines in nodes
              l sep = 12mm,
       forked edge,       % <-- added
          fork sep = 6mm  % <-- added
             }
    [ \begin{tabular}{r@{\hskip=6pt}l} %<-- changed tabcolsep
       Stephanus & Cornellus  \\ 
           ??    & 1234       \\ 
             abc & defghijk
      \end{tabular}% <-- here I remove surplus braces
       [Christina]
       [Maria]
       [Stephanus]
     ]
\end{forest}
%
\end{document}

编辑:一些小改动(删除了edge path = {...}从@cfr 答案中偷来的),在我看来,这让树更漂亮 :)。所有这些都在上面的代码中指定了。

答案2

当您在 Forest 中指定时align,实际上是在给出表格规范。因此,您的代码会尝试将表格嵌套在表格中,这实际上没有必要,而且可能只会创建不必要的空间。

edges此外,尽管加载了库,但您似乎并未使用它,而是在模仿它的forked edges样式。使用预定义的样式并调整父级和分叉之间的距离会更容易。

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[edges,linguistics]{forest}
\usepackage{textcomp}

\begin{document}

\begin{forest}
  forked edges,
  for tree={
    draw,
    fork sep'=1cm,
    minimum height=3cm,
    minimum width=3cm,
    l sep+=2cm,
  }
  [Stephanus & \\ ... & ... \\ abc & äöü, align={ll}
     [Christina]
     [Maria]
     [Stephanus]
   ]
\end{forest}

\end{document}

具有分叉边缘的树状表格

编辑

如果你想为表格指定不同的列间距,你不能写

align={l@{\hskip <dimension>}l}

因为这会扰乱 Forest 的解析器。

但是,你可以做以下两件事之一。

首先,如果要更改两列之间的间距,可以加载array包并创建新的列类型。对于左对齐的列,后跟可变的列间距,

\newcolumntype{k}[1]{l@{\hskip #1}}

允许你写

align={k{2.5pt}l}

如果你想改变树中所有表格的列间距,只需执行相关的 TeX 代码即可。例如,

TeX={\setlength{\tabcolsep}{10pt}}

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[edges,linguistics]{forest}
\usepackage{textcomp,array}
\newcolumntype{k}[1]{l@{\hskip #1}}
\begin{document}
\begin{forest}
  forked edges,
  for tree={
    draw,
    fork sep'=1cm,
    minimum height=3cm,
    minimum width=3cm,
    l sep+=2cm,
  }
  [\multicolumn{2}{l}{Stephanus}  \\ ... & ... \\ abc & äöü, align={ll}
     [Christina]
     [Maria]
     [Stephanus]
   ]
\end{forest}
\begin{forest}
  forked edges,
  for tree={
    draw,
    fork sep'=1cm,
    minimum height=3cm,
    minimum width=3cm,
    l sep+=2cm,
  }
  [\multicolumn{2}{l}{Stephanus}  \\ ... & ... \\ abc & äöü, align={k{2.5pt}l}
     [Christina]
     [Maria]
     [Stephanus]
   ]
\end{forest}
\begin{forest}
  forked edges,
  TeX={\setlength{\tabcolsep}{10pt}},
  for tree={
    draw,
    fork sep'=1cm,
    minimum height=3cm,
    minimum width=3cm,
    l sep+=2cm,
  }
  [\multicolumn{2}{l}{Stephanus}  \\ ... & ... \\ abc & äöü, align={ll}
     [Christina]
     [Maria]
     [Stephanus]
   ]
\end{forest}
\end{document}

演示效果:

间距变化

相关内容