使用 tikz(框架)创建图形

使用 tikz(框架)创建图形

我正在考虑创建一个类似这样的图形: 词汇框架

乍一看,通过 tikz 似乎可以实现

看到 MWE,但说到风格和细化人物,我有点不知所措

  • 让树向下向右生长(代表“Lesart”),
  • “气泡”(Nomen、maus、Lesart)和“箭头”的样式不同,并且箭头结尾没有气泡
  • 具有不同的间距

/顺便问一下,有没有办法改变图形的字体,使其更易读?

你介意在这儿帮忙吗?

\documentclass[
  12pt,
  a4paper,
  headings=standardclasses,
  listof=totoc,
  numbers=noenddot
]{scrartcl}

\usepackage{showframe}
\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.00cm, footskip=1cm]{geometry}
\usepackage[onehalfspacing]{setspace}
\usepackage[main=ngerman, english]{babel}
\usepackage[linguistics]{forest}

\usepackage{tikz}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}

\begin{document}
%
\begin{figure}
\begin{center}
\begin{tikzpicture}[>=stealth, every node/.style={circle, draw, minimum size=0.75cm}]
\graph [tree layout, grow=down, fresh nodes, level distance=1in, sibling distance=0.5in]
    {
         Nomen -> { 
          Maus -> {Genus,Numerus,Register,Flex, Lesart 1 -> {" "," "," "}, Lesart 2 -> {" "," "," "}}
        } 
    };
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}

平均能量损失


更新版本会产生来自同一位置的不必要的箭头配置:

    \documentclass[
  12pt,
  a4paper,
  headings=standardclasses,
  listof=totoc,
  numbers=noenddot
]{scrartcl}

\usepackage{showframe}
\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.00cm, footskip=1cm]{geometry}
\usepackage[onehalfspacing]{setspace}
\usepackage[main=ngerman, english]{babel}
\usepackage[babel, german=quotes]{csquotes}
\usepackage[ngerman]{isodate}
\usepackage[ngerman]{datetime}
%----------------------------------------------------------------------------
%   FIGURES
%----------------------------------------------------------------------------
%\usepackage{graphicx}
%\graphicspath{ {./figures/} }
%\usepackage{lscape}
%\usepackage[final]{pdfpages}
%\usepackage{chngcntr}
\usepackage[linguistics]{forest} % linguistic figures
\usepackage{tikz}
\usetikzlibrary{arrows.meta,decorations.pathmorphing,backgrounds,fit,positioning,shapes.symbols,chains}

\forestset{
east branch/.style = {grow=east, child anchor=west,
                      if level = 3{text width=2ex,draw=none,edge=dashed}{}}
          }% end of forestset




\begin{document}
    \begin{forest}
for tree = {
% node style
    circle,
    draw,
    text width = 4em, text badly centered,
      if level = 2{font=\sffamily\scshape\scriptsize\linespread{0.84}\selectfont}
                  {font=\sffamily\itshape\scriptsize\linespread{0.84}\selectfont},
     inner sep = 1pt,
/tikz/every label/.append style = {align=left, 
    font=\sffamily\scriptsize\linespread{0.84}\selectfont},
% tree style
    child anchor=north,
    edge = {-{Straight Barb[angle=60:2pt 3]}, semithick},
    l sep=12mm,
    s sep=2mm,
           }
% tree body code
[Nomen, double, dashed, label=right: Versuh fuer einem \\
                                     Lexem-Frame fuer \textit{Mause},
    [/maus/, double,
        [Genus              [femin.]]
        [Numerus            [sing.]]
        [Register/\\ Silver [neutral]],
        [Flex.-Klasse   [Sg. I. Pl. S1/U*.,
                         label=right:*Angabe der Flexionklasse hier\\
                                      nach \textsc{Duden-Grammmatic}\textsuperscript{7} 2005
                        ]
        ],
        [Lesart\\ 1,
for tree={east branch},
before computing xy={l=-9mm,s=35mm},
            []  []  []
        ]
        [test\\ 2,
for tree={east branch},
before computing xy={l=+9mm,s=35mm},   
            []  []  []
        ]
    ]
]
    \end{forest}
\end{document}

答案1

还有一个解决方案forest

编辑(1):\forestset通过引入指向东方的分支设置, 略微改进了 MWE 代码。

编辑(2): 增加了newtxtext节点中所有字体均可的包sffamily,修正了节点中的文本。

编辑(3): 修正节点中文本的位置:

\documentclass[margin=3.141592mm]{standalone}
\usepackage{newtxtext}
\usepackage{forest}
\usetikzlibrary{arrows.meta}

\forestset{
east branch/.style = {grow=east, anchor=center, child anchor=west,
                      if level = 3{text width=2ex,draw=none,edge=dashed}{}}
          }% end of forestset


\begin{document}
    \begin{forest}
for tree = {
% node style
    circle,
    draw,
    text width = 3.4em, text badly centered,
     inner sep = 1pt,
        anchor = center,
if level = 2{font=\sffamily\scshape\scriptsize\linespread{0.84}\selectfont}
            {font=\sffamily\scriptsize\linespread{0.84}\selectfont},
if level = 3{font=\sffamily\itshape\scriptsize\linespread{0.84}\selectfont}{},
/tikz/every label/.append style = {align=left, 
    font=\sffamily\scriptsize\linespread{0.84}\selectfont},
% tree style
    child anchor=north,
    edge = {-{Straight Barb[angle=60:2pt 3]}, semithick},
    l sep=12mm,
    s sep=2mm,
           }
% tree body code
[Nomen, double, dashed, label=right: Versuh fuer einem \\
                                     Lexem-Frame fuer \textit{Mause},
    [/maus/, double,
        [Genus              [femin.]]
        [Numerus            [sing.]]
        [Register/\\ Silver [neutral]],
        [Flex.-Klasse   [Sg. I. Pl. S1/U*.,
                         label=right:*Angabe der Flexionklasse hier\\
                                      nach \textsc{Duden-Grammmatic}\textsuperscript{7} 2005
                        ]
        ],
        [Lesart\\ 1,
for tree={east branch},
before computing xy={l=-9mm,s=35mm},
            []  []  []
        ]
        [Lesart\\ 2,
for tree={east branch},
before computing xy={l=+9mm,s=35mm},   
            []  []  []
        ]
    ]
]
    \end{forest}
\end{document}

在此处输入图片描述

新增数量: 如果您的某些森林图使用了该linguistics库,您可以按照以下方式使用它:

  • 在序言中而不是加载\usepackage[linguistics]{forest} 负载
    \usepackage{forest}
    \useforestlibrary{linguistics}
    
  • 当您需要使用forest语言学图表时,请插入\forestapplylibrarydefaults{linguistics}本地组,例如:
    \begingroup
    \forestapplylibrarydefaults{linguistics}
    \begin{forest}
    % forest specification
    % linguistics diagram code
    \end{forest}
    \end{group}
    

请考虑我的森林代码的最新版本。它更简洁,并改进了图表布局。

答案2

欢迎使用 TeX.SX!既然您已经加载了它,为什么不使用这个forest包呢:

\documentclass[
  12pt,
  a4paper,
]{scrartcl}

\usepackage[linguistics]{forest}

\begin{document}
\begin{figure}
\begin{center}

\forestset{
 default preamble={
  for tree={
   circle,
   draw,
   font=\footnotesize,
   edge=->,
   l=25mm,
  }
 },
 eastbound/.style={
  edge path={\noexpand\path[\forestoption{edge}](!u.east)--(.west)\forestoption{edge label};},
  grow=east, 
  ignore,
 },
}

\begin{forest}
 [Nomen, dashed
  [Maus
   [Genus]
   [Numerus]
   [Register]
   [Flex]
   [Lesart 1, before computing xy={l=15mm,s=35mm}, eastbound
    [{},draw=none][{},draw=none][{},draw=none]] 
   [Lesart 2, before computing xy={l=-5mm,s=35mm}, eastbound
    [{},draw=none][{},draw=none][{},draw=none]] 
  ]
 ]
\end{forest}

\end{center}
\end{figure}

\end{document}

在此处输入图片描述


编辑:您可以简化边缘路径设置并自动处理空节点:

\documentclass[
  12pt,
  a4paper,
]{scrartcl}

\usepackage[linguistics]{forest}

\begin{document}
\begin{figure}
\begin{center}

\forestset{
 default preamble={
  for tree={
   circle,
   draw,
   font=\footnotesize,
   edge=->,
   edge path={\noexpand\path[\forestoption{edge}](!u)--()\forestoption{edge label};},
   l=25mm,
  },
  delay={
   where content={}{
    draw=none,
    edge=dashed,
   }{},
  }
 },
}

\begin{forest}
 [Nomen, dashed
  [Maus
   [Genus]
   [Numerus]
   [Register]
   [Flex]
   [Lesart 1, before computing xy={l=15mm,s=35mm}, grow=east, ignore
    [][][]] 
   [Lesart 2, before computing xy={l=-5mm,s=35mm}, grow=east, ignore
    [][][]] 
  ]
 ]
\end{forest}

\end{center}
\end{figure}

\end{document}

在此处输入图片描述


也可以看看:森林:同一层树枝的生长方向不同

相关内容