在 tikz 中绘图

在 tikz 中绘图

我怎样才能在 LaTEX 文档中绘制这个图形?

在此处输入图片描述

答案1

一种选择:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,positioning,arrows.meta}

\begin{document}

\begin{tikzpicture}[
  mylin/.style={help lines,black!70},
  arr/.style={>=Triangle,mylin,<->},
]
\path
  node  (info1) {Hole detection} 
  node[right=0pt of info1] (info2) {Data transmission}
  node[right=0pt of info2] (info3) {\ldots}
  node[draw,fit={(info1) (info3)}] (frame) {};
\draw[mylin]
  ([yshift=20pt]frame.north west) -- ([yshift=-20pt]frame.south west)
  (info1.north east|-frame.north) -- ([yshift=-20pt]{info1.south east|-frame.south})
  ([yshift=20pt]{info2.north east|-frame.north}) -- ([yshift=-20pt]{info2.south east|-frame.south});
\draw[arr]
  ([yshift=-10pt]frame.south west) -- node[fill=white] {$a$} ([yshift=-10pt]{info1.south east|-frame.south});  
\draw[arr]
  ([yshift=-10pt]{info1.south east|-frame.south}) -- node[fill=white] {$1-a$} ([yshift=-10pt]{info2.south east|-frame.south});  
\draw[arr]
  ([yshift=10pt]frame.north west) -- node[fill=white] {time slot $(k)$} ([yshift=10pt]{info2.north east|-frame.north});  
\draw[arr,->]
  (frame.south east) -- ++(20pt,0);
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

修改版本以使用新命令来注释箭头。

\documentclass[border=4pt]{standalone}
\usepackage{tikz}

\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[scale=1]
\tikzset{box/.style={draw,thick,outer sep=0,minimum height=2em}}
\tikzset{arr/.style={>=Triangle,help lines,black!70,<->}}
\newcommand{\arrann}[5][]%
{
  \draw[>={Triangle[open]},help lines,black!70,<->,#1]
  ([yshift=#5]#2) -- node[fill=white] {#3} ([yshift=#5]#4);
  \draw[help lines,black!70] (#2) -- ([yshift={2*#5}]#2)
      (#4) -- ([yshift={2*#5}]#4);
}
\path node[box]  (info1) {Hole detection} 
  node[box,right=0pt of info1] (info2) {Data transmission}
  node[box,right=0pt of info2] (info3) {\ldots};
\draw[arr,->] (info3.south east) -- ++(20pt,0);
\arrann[draw=red!50]{info1.south west}{$a$}{info1.south east}{-10pt};
\arrann{info2.south west}{$1-a$}{info2.south east}{-10pt};
\arrann{info1.north west}{$(k)$}{info2.north east}{10pt}; 
\end{tikzpicture}
\end{document}

输出: 在此处输入图片描述

相关内容