树木

树木

我尝试设置两行节点,但如您所见,节点未水平对齐,因此箭头偏离。我该如何修复此问题?

结果在此处输入图片描述

平均能量损失

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning,shadows,shapes,arrows}

\begin{document}

\tikzstyle{abstract}=[rectangle, draw=black, rounded corners, fill=blue, drop shadow,
text centered, anchor=north, text=white, text width=3cm, text justified]
\tikzstyle{comment}=[rectangle, draw=black, rounded corners, fill=blue!70, drop shadow,
text centered, anchor=north, text=white, text width=3cm]
\tikzstyle{myarrow}=[->, >=open triangle 90, thick]
\tikzstyle{line}=[-, thick]

%\begin{minipage}{0.6\textwidth}
\begin{center}
\begin{tikzpicture}[node distance=2cm]

   %Person node
   \node (Node-A) [abstract, rectangle split, rectangle split parts=2]
   {
      \textbf{News}
      \nodepart{second}Date\newline ...
   };

   %Media node
   \node (Node-B) [abstract, rectangle split, rectangle split parts=2, below=of Node-A]
   {
      \textbf{Media}
      \nodepart{second}
   };

   %Authors node
   \node (Node-B-1) [abstract, rectangle split, rectangle split parts=2, left=of Node-B]
   {
      \textbf{Authors}
      \nodepart{second} Person
   };

   %Audience node
   \node (Node-B+1) [abstract, rectangle split, rectangle split parts=2, right=of Node-B]
   {
      \textbf{Audience}
      \nodepart{second}Person\newline Company
   };

   \draw[myarrow] (Node-B-1.north) -- ++(0,0.8) -| (Node-A.south);
   \draw[line] (Node-B.north) -- ++(0,0.8) -| (Node-A.south);
   \draw[line] (Node-B+1.north) -- ++(0,0.8) -| (Node-A.south);

\end{tikzpicture}
\end{center}
%\end{minipage}

\end{document}

答案1

快速修复:例如,您可以使用特定的锚点,例如设置left=of NodeB.north west,anchor=north east,反之亦然。

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning,shadows,shapes,arrows}

\tikzset{abstract/.style={rectangle, draw=black, rounded corners, fill=blue, drop shadow,
text centered, anchor=north, text=white, text width=3cm, text justified},
comment/.style={rectangle, draw=black, rounded corners, fill=blue!70, drop shadow,
text centered, anchor=north, text=white, text width=3cm},
myarrow/.style={->, >=open triangle 90, thick},
line/.style={-, thick}
}
\begin{document}



%\begin{minipage}{0.6\textwidth}
\begin{center}
\begin{tikzpicture}[node distance=2cm]

   %Person node
   \node (Node-A) [abstract, rectangle split, rectangle split parts=2]
   {
      \textbf{News}
      \nodepart{second}Date\newline ...
   };

   %Media node
   \node (Node-B) [abstract, rectangle split, rectangle split parts=2, below=of Node-A]
   {
      \textbf{Media}
      \nodepart{second}
   };

   %Authors node
   \node (Node-B-1) [abstract, rectangle split, rectangle split parts=2, left=of Node-B.north west,anchor=north east]
   {
      \textbf{Authors}
      \nodepart{second} Person
   };

   %Audience node
   \node (Node-B+1) [abstract, rectangle split, rectangle split parts=2, right=of Node-B.north east,anchor=north west]
   {
      \textbf{Audience}
      \nodepart{second}Person\newline Company
   };

   \draw[myarrow] (Node-B-1.north) -- ++(0,0.8) -| (Node-A.south);
   \draw[line] (Node-B.north) -- ++(0,0.8) -| (Node-A.south);
   \draw[line] (Node-B+1.north) -- ++(0,0.8) -| (Node-A.south);

\end{tikzpicture}
\end{center}
%\end{minipage}

\end{document}

树木

简单的基于树的方法。

\documentclass[border=4mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows,shapes,arrows,calc}

\tikzset{abstract/.style={rectangle, draw=black, rounded corners, fill=blue, drop shadow,
text centered, text=white, anchor=north,text width=3cm, text justified,rectangle split, rectangle split parts=2},
comment/.style={rectangle, draw=black, rounded corners, fill=blue!70, drop shadow,
text centered, anchor=north, text=white, text width=3cm},
myarrow/.style={->, >=open triangle 90, thick},
line/.style={-, thick}
}
\begin{document}

\begin{tikzpicture}[
  sibling distance=4cm,
  edge from parent path={
     (\tikzparentnode.south) --
     ($(\tikzparentnode.south)!0.5!(\tikzparentnode.south |- \tikzchildnode.north) $) -|
     (\tikzchildnode.north)},
  edge from parent/.append style={line}]

   %Person node
   \node (toplevel) [abstract]
   {
      \textbf{News}
      \nodepart{second}Date\newline ...
   }
   %Media node
  child {  node [abstract]
   {
      \textbf{Media}
      \nodepart{second}
   }
   }
   %Authors node
   child {node [abstract]
   {
      \textbf{Authors}
      \nodepart{second} Person
   }
   }
   %Audience node
   child { node (Node-B+1) [abstract]
   {
      \textbf{Audience}
      \nodepart{second}Person\newline Company
   }};

\draw [myarrow] (toplevel-2) -- (toplevel);

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容