TIkZ 中箭头的自定义起点

TIkZ 中箭头的自定义起点

我有以下代码:

\begin{center}
\begin{tabular}{c c c c c}
    T1 & T2 & T3 & T4 & T5 \\
    & & & & Read x \tikzmark{a}  \\
    Read x \tikzmark{b} \\
    & Write x \tikzmark{c} \\
    Read y \tikzmark{d} \\
    & & Read y \tikzmark{e}  \\
    & & Write z \tikzmark{f} \\
    & & & Write x \tikzmark{g} \\
    & & & & Write y \tikzmark{h}  \\
    & & & & Read z \tikzmark{i} \\
    & & & & Commit \tikzmark{g} 
\end{tabular}
\begin{tikzpicture}[overlay, remember picture, shorten >=.5pt, shorten <=.5pt, transform canvas={yshift=.25\baselineskip}]
    \draw [->] ({pic cs:a}) -- ({pic cs:b});
    \draw [->] ({pic cs:a}) -- ({pic cs:c});
    \draw [->] ([yshift=.75pt]{pic cs:aa}) -- ({pic cs:bb});
\end{tikzpicture}
\end{center}

我得到的输出是:

我正在寻找一种方法来编辑箭头的起点和终点,以便它们不会超出内容。TIA

答案1

您可以将以下内容放在tikzmark单元格内容之前:

在此处输入图片描述

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

\begin{center}
\begin{tabular}{c c c c c}
    T1 & T2 & T3 & T4 & T5 \\
    & & & & \tikzmark{a} Read x   \\
    Read x \tikzmark{b} \\
    & Write x \tikzmark{c} \\
    Read y \tikzmark{d} \\
    & & Read y \tikzmark{e}  \\
    & & Write z \tikzmark{f} \\
    & & & Write x \tikzmark{g} \\
    & & & & Write y \tikzmark{h}  \\
    & & & & Read z \tikzmark{i} \\
    & & & & Commit \tikzmark{g} 
\end{tabular}
\begin{tikzpicture}[overlay, remember picture, shorten >=.5pt, shorten <=.5pt, transform canvas={yshift=.25\baselineskip}]
    \draw [->] ({pic cs:a}) -- ({pic cs:b});
    \draw [->] ({pic cs:a}) -- ({pic cs:c});
    %\draw [->] ([yshift=.75pt]{pic cs:aa}) -- ({pic cs:bb});
\end{tikzpicture}
\end{center}

\end{document}

或者,您可以使用\tikzmarknode它为您的 tikzpicture 提供更自然的绘图命令。正如@Qrrbrbirlbel 所建议的,您可以调整outer sep而不是使用shorten

在此处输入图片描述

\documentclass{文章}

\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

\begin{center}
\begin{tabular}{c c c c c}
    T1 & T2 & T3 & T4 & T5 \\
    & & & & \tikzmarknode[outer sep=1mm]{a}{Read x}   \\
    \tikzmarknode[outer sep=1mm]{b}{Read x} \\
    & \tikzmarknode[outer sep=1mm]{c}{Write x} \\
    \tikzmarknode{d}{Read y} \\
    & & \tikzmarknode{e}{Read y}  \\
    & & \tikzmarknode{f}{Write z} \\
    & & & \tikzmarknode{g}{Write x} \\
    & & & & \tikzmarknode{h}{Write y}  \\
    & & & & \tikzmarknode{i}{Read z} \\
    & & & & \tikzmarknode{j}{Commit} 
\end{tabular}
\begin{tikzpicture}[overlay, remember picture]
    \draw [->] (a.west) -- (b.east);
    \draw [->] (a.west) -- (c.east);
    %\draw [->] ([yshift=.75pt]{pic cs:aa}) -- ({pic cs:bb});
\end{tikzpicture}
\end{center}

\end{document}

相关内容