如何在 latex 中绘制图形的剖面图

如何在 latex 中绘制图形的剖面图

我想在图中画一条线,就像一条从 到sourcegammasourcealphasource的边穿过的线omega。我这样做是为了演示网络中的最小割点 ((算法分析))

\begin{tikzpicture}
[scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
\tikzset{vertex/.style = {shape=circle,draw,minimum size=1.5em}}
\tikzset{edge/.style = {->,> = latex'}}

  \node (s) at (0,5){source};
  \node (v1) at (5,9){alpha};
  \node (v4) at (13,9){beta};
  \node (v2) at (5,1){omega};
  \node (v3) at (6,5){gamma};
  \node (v5) at (13,1){theta};
  \node (v6) at (16,5){delta};
  \node (t) at (20,5){sink};

\tikzset{EdgeStyle/.style={->}}
\Edge[label=$1/1$](s)(v1);
\Edge[label=$4/4$](s)(v2);
\Edge[label=$2/2$](s)(v3);
\Edge[label=$2/2$](v2)(v4);
\Edge[label=$2/2$](v2)(v5);
\Edge[label=$1/1$](v1)(v4);
\Edge[label=$1/1$](v3)(v4);
\Edge[label=$4/4$](v6)(t);
\Edge[label=$1/1$](v5)(t);
\Edge[label=$2/2$](v4)(t);
\Edge[label=$1/4$](v5)(v6);
\Edge[label=$1/1$](v3)(v6);
\Edge[label=$2/2$](v4)(v6);


\end{tikzpicture}

答案1

使用 calc 库你可以这样说

\draw[dashed] 
  ([yshift=60pt]$ (s)!0.5!(v1) $ ) -- 
  ([yshift=-60pt]$ (s)!0.5!(v2) $ );

完整示例:

\documentclass{article}
\usepackage{tkz-graph}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
[scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
\tikzset{vertex/.style = {shape=circle,draw,minimum size=1.5em}}
\tikzset{edge/.style = {->,> = latex'}}

  \node (s) at (0,5){source};
  \node (v1) at (5,9){alpha};
  \node (v4) at (13,9){beta};
  \node (v2) at (5,1){omega};
  \node (v3) at (6,5){gamma};
  \node (v5) at (13,1){theta};
  \node (v6) at (16,5){delta};
  \node (t) at (20,5){sink};

\tikzset{EdgeStyle/.style={->}}
\Edge[label=$1/1$](s)(v1);
\Edge[label=$4/4$](s)(v2);
\Edge[label=$2/2$](s)(v3);
\Edge[label=$2/2$](v2)(v4);
\Edge[label=$2/2$](v2)(v5);
\Edge[label=$1/1$](v1)(v4);
\Edge[label=$1/1$](v3)(v4);
\Edge[label=$4/4$](v6)(t);
\Edge[label=$1/1$](v5)(t);
\Edge[label=$2/2$](v4)(t);
\Edge[label=$1/4$](v5)(v6);
\Edge[label=$1/1$](v3)(v6);
\Edge[label=$2/2$](v4)(v6);

\draw[dashed] 
  ([yshift=60pt]$ (s)!0.5!(v1) $ ) -- 
  ([yshift=-60pt]$ (s)!0.5!(v2) $ );

\end{tikzpicture}

\end{document} 

在此处输入图片描述

答案2

事后,你可以用以下方法将剪切添加到图片的外部\stackinset

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{tkz-graph}
\usetikzlibrary{calc}
\usepackage{graphicx}
\usepackage{stackengine}
% DASHED LINE OF SPECIFIED LENGTH
% From morsburg at http://tex.stackexchange.com/questions/12537/
% how-can-i-make-a-horizontal-dashed-line/12553#12553
\def\dashfill{\cleaders\hbox to .6em{-}\hfill}
\newcommand\dashline[1]{\hbox to #1{\dashfill\hfil}}
\begin{document}
\savestack{\mygraph}{\begin{tikzpicture}
[scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
\tikzset{vertex/.style = {shape=circle,draw,minimum size=1.5em}}
\tikzset{edge/.style = {->,> = latex'}}
  \node (s) at (0,5){source};
  \node (v1) at (5,9){alpha};
  \node (v4) at (13,9){beta};
  \node (v2) at (5,1){omega};
  \node (v3) at (6,5){gamma};
  \node (v5) at (13,1){theta};
  \node (v6) at (16,5){delta};
  \node (t) at (20,5){sink};
\tikzset{EdgeStyle/.style={->}}
\Edge[label=$1/1$](s)(v1);
\Edge[label=$4/4$](s)(v2);
\Edge[label=$2/2$](s)(v3);
\Edge[label=$2/2$](v2)(v4);
\Edge[label=$2/2$](v2)(v5);
\Edge[label=$1/1$](v1)(v4);
\Edge[label=$1/1$](v3)(v4);
\Edge[label=$4/4$](v6)(t);
\Edge[label=$1/1$](v5)(t);
\Edge[label=$2/2$](v4)(t);
\Edge[label=$1/4$](v5)(v6);
\Edge[label=$1/1$](v3)(v6);
\Edge[label=$2/2$](v4)(v6);
\end{tikzpicture}}
\stackinset{c}{7cm}{c}{}{\rotatebox{90}{\dashline{2in}}}{%
\stackinset{c}{-4.6cm}{c}{-1.5cm}{\rotatebox{-38}{\dashline{3.2in}}}{%
\stackinset{c}{}{c}{1cm}{\dashline{6in}}{%
\mygraph}}}
\end{document}

在此处输入图片描述

相关内容