如何获得表格内弯曲箭头的美观且理想的路径或控制其端点?

如何获得表格内弯曲箭头的美观且理想的路径或控制其端点?

我想要绘制以下内容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}

带有箭头的网格

相关内容