用 latex 画线

用 latex 画线

如何在 latex 中绘制线条和字符串

我有这个数字: 在此处输入图片描述

这是我的代码

\documentclass{article}
\usepackage{tikz}

\newcommand{\linkeditem}[1]{
  \begin{tikzpicture}[remember picture]%
  \node (#1) [gray,circle,fill,inner sep=1.5pt]{};
  \end{tikzpicture}%
}

\newenvironment{linkedlist}{%
    \renewcommand{\theenumi}{\protect\linkeditem{\arabic{enumi}}}
    \renewcommand{\labelenumi}{\theenumi}
    \begin{enumerate}
}{ \end{enumerate} \begin{tikzpicture}[remember picture,overlay]
  \ifnum\value{enumi}>1% Only if there are at least 2 bullet points
  \foreach \x [remember=\x as \lastx (initially 1)] 
    in {2,...,\value{enumi}}{% iterate over them
    \draw[gray, shorten >=1mm, shorten <=1mm] (\lastx) -- (\x);}% and draw the connecting lines
  \fi
  \end{tikzpicture}
}

\begin{document}

\begin{linkedlist}
  \item tiempo presion
  \item ultimo keyPress
  \item tiempo realce
\end{linkedlist}

\end{document}

答案1

这就是你需要的吗?

\documentclass[tikz,margin=3mm]{standalone}
\renewcommand{\rmdefault}{\sfdefault}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[
    every node/.style={minimum width=2cm},
    decoration={
        markings,
        mark=at position 0 with {\arrow{|}},
        mark=at position 1 with {\arrow{|}}
    }
]
\draw[fill=gray!10,rounded corners=3pt] (0,0) rectangle (6,4);
\node (kd) at (1,3.5) {keyDown};
\foreach \i in {3,2.5,1}
    \node (kp\i) at (1,\i) {keyPress};
\node (ku) at (1,.5) {keyUp};
\foreach \i in {1.5,1.75,2}
    \fill[black] (1,\i) circle (1pt);
\draw[postaction={decorate}] (kd.east)--(kp1.east) node[midway,right] {tiempo de presion};
\draw[postaction={decorate},blue] (kp1.east)--(ku.east) node[midway,right,black] {tiempo de realce};
\node[minimum width=2.5cm] (uk) at (4.5,1.5) {ultimo keyPress};
\draw[->,red] (kp1.east)--(uk.west);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容