如何獲得表格內彎曲箭頭的漂亮且理想的路徑或控制它們的端點?

如何獲得表格內彎曲箭頭的漂亮且理想的路徑或控制它們的端點?

我想繪製以下內容LaTeX(當然以一種看起來更漂亮的方式):

在此輸入影像描述

到目前為止我已經達到以下目標。

\documentclass{article}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{% <---- BEWARE
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
\usetikzlibrary{tikzmark}

\begin{document}
  \begin{tabular}{cccccccc}
\cline{4-5}
 & & & \multicolumn{1}{|c}{\circled{M1}}\tikzmark{b} & \multicolumn{1}{|c|}{M2} & & & \\
\cline{4-5}
 & & & \multicolumn{1}{|c}{R1} & \multicolumn{1}{|c|}{R2} & & & \\
\cline{4-5}
 & & &  &  & & & \\
\cline{1-2}\cline{4-5}\cline{7-8}
\multicolumn{1}{|c|}{\circled{M1}}\tikzmark{a}&\multicolumn{1}{c|}{M2} & & \multicolumn{1}{|c}{\circled{M1}}\tikzmark{x} & \multicolumn{1}{|c|}{M2} & & \multicolumn{1}{|c}{\circled{M1}}\tikzmark{c} & \multicolumn{1}{|c|}{M2} \\
\cline{1-2}\cline{4-5}\cline{7-8}
\multicolumn{1}{|c|}{R1}&\multicolumn{1}{c|}{R2} & & R1 & R2 & & \multicolumn{1}{|c}{R1} & \multicolumn{1}{|c|}{R2} \\
\cline{1-2}\cline{4-5}\cline{7-8}
 & & &  &  & & & \\
\cline{4-5}
 & & & \multicolumn{1}{|c}{\circled{M1}}\tikzmark{d} & \multicolumn{1}{|c|}{M2} & & & \\
\cline{4-5}
 & & & \multicolumn{1}{|c}{R1} & \multicolumn{1}{|c|}{R2} & & & \\
\cline{4-5}
  \end{tabular}
  \begin{tikzpicture}[overlay, remember picture, yshift=.25\baselineskip, shorten >=.5pt, shorten <=.5pt]
    \draw [->] ({pic cs:a}) [bend right] to ({pic cs:x});
    \draw [->] ({pic cs:b}) [bend right] to ({pic cs:x});
    \draw [->] ({pic cs:c}) [bend right] to ({pic cs:x});
    \draw [->] ({pic cs:d}) [bend right] to ({pic cs:x});
  \end{tikzpicture}
\end{document}

我無法控制箭頭,它們似乎傾向於在一個特定點結束。我如何選擇終點在哪裡?或者也許 LaTeX 中的某些東西會自動為箭頭設定一些路徑,以便它們與圖中最少的位置相交?

答案1

這是一個沒有 tikzmark 的版本,它透過為您已在命令中建立的節點分配不同的名稱來運作\circled


\documentclass{article}
%\url{https://tex.stackexchange.com/q/563076/86}
\usepackage{tikz}
\newcommand*\circled[2][char]{\tikz[baseline=(#1.base),remember picture]{% <---- BEWARE
            \node[shape=circle,draw,inner sep=2pt] (#1) {#2};}}

\begin{document}
  \begin{tabular}{cccccccc}
\cline{4-5}
 & & & \multicolumn{1}{|c}{\circled[b]{M1}} & \multicolumn{1}{|c|}{M2} & & & \\
\cline{4-5}
 & & & \multicolumn{1}{|c}{R1} & \multicolumn{1}{|c|}{R2} & & & \\
\cline{4-5}
 & & &  &  & & & \\
\cline{1-2}\cline{4-5}\cline{7-8}
\multicolumn{1}{|c|}{\circled[a]{M1}}&\multicolumn{1}{c|}{M2} & & \multicolumn{1}{|c}{\circled[x]{M1}}& \multicolumn{1}{|c|}{M2} & & \multicolumn{1}{|c}{\circled[c]{M1}} & \multicolumn{1}{|c|}{M2} \\
\cline{1-2}\cline{4-5}\cline{7-8}
\multicolumn{1}{|c|}{R1}&\multicolumn{1}{c|}{R2} & & R1 & R2 & & \multicolumn{1}{|c}{R1} & \multicolumn{1}{|c|}{R2} \\
\cline{1-2}\cline{4-5}\cline{7-8}
 & & &  &  & & & \\
\cline{4-5}
 & & & \multicolumn{1}{|c}{\circled[d]{M1}} & \multicolumn{1}{|c|}{M2} & & & \\
\cline{4-5}
 & & & \multicolumn{1}{|c}{R1} & \multicolumn{1}{|c|}{R2} & & & \\
\cline{4-5}
  \end{tabular}
  \begin{tikzpicture}[overlay, remember picture, yshift=.25\baselineskip, shorten >=.5pt, shorten <=.5pt]
    \draw [->] (a) [bend right] to (x);
    \draw [->] (b) [bend right] to (x);
    \draw [->] (c) [bend right] to (x);
    \draw [->] (d) [bend right] to (x);
  \end{tikzpicture}
\end{document}

網格之間有箭頭

相關內容