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

时间:2015-12-12 05:53:55

标签: latex tikz graph-drawing

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

这是我的代码:

SendGridMessage message = new SendGridMessage();
message.AddTo(new List<string>() { "user1@abc.com", "user2@xyz.com", "user3@abc.com", "user4@xyz.com" });

有人可以告诉我如何才能获得这种效果吗?

谢谢!

3 个答案:

答案 0 :(得分:1)

This TeX.SX answer显示了如何将pathnode应用到node的两个\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} 的中点:

    Month,Actual,Forecast,Budget
    Jul-14,200000,-,74073.86651
    Aug-14,198426.57,-,155530.2499
    Sep-14,290681.62,-,220881.4631
    Oct-14,362974.9,-,314506.6437
    Nov-14,397662.09,-,382407.67
    Dec-14,512434.27,-,442192.1932
    Jan-15,511470.25,511470.25,495847.6137
    Feb-15,-,536472.5467,520849.9105
    Mar-15,-,612579.9047,596957.2684
    Apr-15,-,680936.5086,465313.8723
    May-15,-,755526.7173,739904.081
    Jun-15,-,811512.772,895890.1357

screenshot of output

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

答案 1 :(得分:1)

为那些可能也坚持使用它的人提供答案。

您需要创建辅助坐标并为其绘制一条线 (我正在使用xetex)

% Preamble
\usepackage{tikz-uml}
\usetikzlibrary{positioning}
% Preamble end
...
\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$};

  % Add Aux points
  \coordinate[yshift=0.6cm, right=1cm of B1.east] (aux1);
  \coordinate[yshift=1.6cm, right=0.1cm of A1.east] (aux2);

  % Your desired arrows
  \draw [arrow] (C1.east) to (aux1); % or (C1.east) -- (aux1) if you need multiple operations further
  % Below are three examples of a relatively same result
  \draw [arrow] (C1.south east) .. controls (1.4,3.5) .. (aux2);  
  % \draw [arrow] (C1.south east) to [bend left=24] (aux2);
  % \draw [arrow] (C1.south east) -| ([shift={(0.5cm,0cm)}]C1.south east) -- (aux2); % pointy arrow

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

\end{tikzpicture}

enter image description here

答案 2 :(得分: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