在 tikz qtree 中在框附近绘制圆圈

在 tikz qtree 中在框附近绘制圆圈

我正在尝试在节点上方绘制:

  1. 一个圆圈
  2. 一些文本

在此处输入图片描述

但我不知道该怎么做。这是我的临时代码

\begin{figure}
\captionof{figure}{Estructura del análisis de árbol lógico }
\centering
\begin{tikzpicture}
\tikzset{edge from parent/.style={draw,edge from parent path={(\tikzparentnode.south)-- +(0,-8pt)-| (\tikzchildnode)}}}
\tikzset{every tree node/.style={align=center,anchor=north}}
\Tree [.{Modo de falla}
[.\node[draw]{Bajo condiciones normales \\ ¿Los operarios pudieron determinar que algo ocurria?}; 
[.Si [.\node[draw]{¿Este modo de falla \\ causo un problema de seguridad?};]
]
[.No [.\node[draw]{Falla oculta};]
]
]]

\end{tikzpicture}
\captionsetup{font={footnotesize,it}, width=\textwidth}
\caption*{Fuente: El autor.}
\label{fig:arbol_logico}
\end{figure}

它看起来是这样的(看起来很糟糕:))

在此处输入图片描述

答案1

使用原始方法的树tikz-qtree

在此处输入图片描述

代码:

\documentclass{article}
\usepackage[spanish]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz-qtree}
\usepackage{caption}

\begin{document}

\begin{figure}
\captionof{figure}{Estructura del análisis de árbol lógico }
\centering
\begin{tikzpicture}
\tikzset{edge from parent/.style={draw,edge from parent path={(\tikzparentnode.south)-- +(0,-8pt)-| (\tikzchildnode)}}}
\tikzset{
  every tree node/.style={
    draw,
    align=center,
    anchor=north,
    text width=5cm,
    font=\sffamily
    },
  level 1/.style={level distance=1.5cm},
  level distance=2.5cm,
  sibling distance=30pt,
}
\Tree 
[.\node[draw=none] {Modo de falla};
  [.\node (normales) {Bajo condiciones normales, ¿los operarios pudieron determinar que algo ocurría?}; \edge node[fill=white,near end,font=\sffamily] {Sí}; 
    [.\node (problema) {¿Este modo de falla causó un problema de seguridad?};
    ]
      \edge node[fill=white,near end,font=\sffamily] {No};
    [.\node[text width=3cm] (fallaocul) {Falla oculta};
    ]
  ]
]
\node[circle,draw,anchor=south east,font=\sffamily] 
  at ([yshift=6pt]fallaocul.north east) {D};
\node[anchor=south east,font=\sffamily] 
  at (normales.north east) {(1) Evidente};
\node[anchor=south east,font=\sffamily] 
  at (problema.north east) {(2) Seguridad};
\end{tikzpicture}
\captionsetup{font={footnotesize,it}, width=\textwidth}
\caption*{Fuente: El autor.}
\label{fig:arbol_logico}
\end{figure}

\end{document}

这个想法是给节点分配名称,然后使用这些名称将标签放置在所需的位置。

答案2

嗯...它是一棵树,所以我建议使用forest它来更好地处理树。

通常,我在图表中使用无衬线字体,但如果您不喜欢,可以删除我的调整;)。

以下是一个例子:

\documentclass[tikz,border=5pt,multi]{standalone}
\usepackage{forest}
\usepackage[utf8]{inputenc}
\usepackage{cfr-lm}
\usetikzlibrary{positioning}
\begin{document}
{\sffamily\plstyle
\begin{forest}
  create my label/.style n args=2{
    tikz={\node [font=\small, thick, anchor=south east, inner xsep=0pt, #1] at (.north east) {#2};}
  },
  my label/.style={
    create my label={}{#1}
  },
  my circle label/.style={
    create my label={draw, circle, yshift=5pt}{#1}
  },
  for tree={
    align=center,
    parent anchor=south,
    child anchor=north,
    where level=0{}{l sep+=1em},
    thick,
    edge={thick, rounded corners=2pt},
    rounded corners=2pt,
    edge path={
      \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-5pt) -| (.child anchor)\forestoption{edge label};
    },
    draw,
  }
  [Modo de falla
  [{Bajo condiciones normales\\¿Los operarios pudieron determinar que algo ocurría?}, my label={(1) Evidente}
  [ {¿Este modo de falla\\causó un problema de seguridad?}, edge label={node [pos=.75, fill=white]{Si}}, my label={(2) Seguridad}
      ]
      [Falla oculta, edge label={node [pos=.75, fill=white]{No}}, my circle label=D
      ]
    ]
  ]
\end{forest}}
\end{document}

输出如下:

森林里的树

相关内容