Tikz:从节点到另一边缘的标签绘制边缘

问题描述 投票:3回答:2

我试图找出如何在tikz中的节点和两个其他节点之间的边缘标签之间绘制边缘。这是我正在尝试做的一个例子:enter image description here

这是我的代码:

\documentclass[11pt]{article}
\usepackage[margin=1in, top=1.5in]{geometry}
\usepackage{amsmath,amssymb,bbm}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning}

\setlength{\parindent}{0.25in}
\newcommand{\assign}{:=}
\usepackage[hang,small,bf]{caption}


\begin{document}

\begin{figure}[!h]
  \centering
  \begin{tikzpicture}[shorten >=1pt,node distance=3cm,on grid,auto]
    \tikzstyle{state}=[shape=circle,thick,draw,minimum size=1.5cm]

    \node[state] (A1) {$A_1$};
    \node[state,above of=A1] (B1) {$B_1$};
    \node[state,above of=B1] (C1) {$C_1$};

    \node[state,right of=A1] (A2) {$A_2$};
    \node[state,above of=A2] (B2) {$B_2$};
    \node[state,above of=B2] (C2) {$C_2$};



    \path[->,draw,thick]
    (A1) edge node {$l_A$} (B2)
    (B1) edge node {$l_B$} (B2)

    ;

  \end{tikzpicture}
  \caption{Model}
  \label{fig:f1}
\end{figure}


\end{document}

谁能告诉我怎么能得到这种效果?

谢谢!

latex tikz graph-drawing
2个回答
1
投票

This TeX.SX answer展示了如何将path中的node应用到两个nodes的中点:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=3cm,auto]%,on grid
\tikzstyle{state}=[shape=circle,thick,draw,minimum size=1.5cm]

\node[state] (A1) {$A_1$};
\node[state,above of=A1] (B1) {$B_1$};
\node[state,above of=B1] (C1) {$C_1$};

\node[state,right of=A1] (A2) {$A_2$};
\node[state,above of=A2] (B2) {$B_2$};
\node[state,above of=B2] (C2) {$C_2$};

\path [->,draw,thick] (C1) -- ($ (B1) !.5! (B2) $);
\path [->,draw,thick] (C1) -- ($ (A1) !.5! (B2) $);

\path[->,draw,thick]
  (A1) edge node[near start] {$l_A$} (B2)
  (B1) edge node[near end] {$l_B$} (B2);

\end{tikzpicture}
\end{document}

screenshot of output

这只是一个粗略的起点:请发表评论说这个草图是否合适,或者您是否想要进一步开发。


0
投票

根据文件,

您也可以将选项name=<name>添加到option列表中;它具有相同的效果[与使用(name)提供节点名称]

在您的示例中,这给出了:

\documentclass[11pt]{article}
\usepackage[margin=1in, top=1.5in]{geometry}
\usepackage{amsmath,amssymb,bbm}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning}

\setlength{\parindent}{0.25in}
\newcommand{\assign}{:=}
\usepackage[hang,small,bf]{caption}


\begin{document}

\begin{figure}[!h]
  \centering
  \begin{tikzpicture}[shorten >=1pt,node distance=3cm,on grid,auto]
    \tikzstyle{state}=[shape=circle,thick,draw,minimum size=1.5cm]

    \node[state] (A1) {$A_1$};
    \node[state,above of=A1] (B1) {$B_1$};
    \node[state,above of=B1] (C1) {$C_1$};

    \node[state,right of=A1] (A2) {$A_2$};
    \node[state,above of=A2] (B2) {$B_2$};
    \node[state,above of=B2] (C2) {$C_2$};



    \path[->,draw,thick]
    (A1) edge node[name=la] {$l_A$} (B2)
    (B1) edge node[name=lb] {$l_B$} (B2)

    ;
    \draw[->, thick, bend left=15]  (C1) edge (la) edge (lb); 

  \end{tikzpicture}
  \caption{Model}
  \label{fig:f1}
\end{figure}


\end{document}

screenshot of output

© www.soinside.com 2019 - 2024. All rights reserved.