3

Consider the code below, which produces the tables shown at the bottom of this message. Is it possible to automatically adjust the starting and ending coordinates of the arrows, so that the arrow starts and ends at a table border (likewise the first arrow in figure below)? Thanks!

\documentclass{article}
\usepackage{mlmodern}
\usepackage{tikz}
\usepackage{array}

\usetikzlibrary{calc, tikzmark, arrows.meta}

\begin{document}

\begin{minipage}{0.2\textwidth} % Adjusted minipage width
\centering
\begin{tabular}{|c|c|}
\hline
\multicolumn{2}{|c|}{Table 1} \\
\hline
Node & Value \\
\hline
\(\mathbf{A_1}\) & 100 \tikzmark{A1} \\
\hline
\(\mathbf{A_2}\) & 200 \tikzmark{A2} \\
\hline
\end{tabular}
\end{minipage}
\hspace{1cm} % Adjust the separation width here
\begin{minipage}{0.2\textwidth} % Adjusted minipage width
\centering
\begin{tabular}{|c|c|}
\hline
\multicolumn{2}{|c|}{Table 2} \\
\hline
\tikzmark{B1} Node* & Value \\
\hline
\(\mathbf{B_1}\) & 300 \\
\hline
\tikzmark{B2}\(\mathbf{B_2}\) & 400 \\
\hline
\end{tabular}
\end{minipage}

\begin{tikzpicture}[remember picture, overlay]
  \draw[->, thick, -{Latex[length=2mm]}, line width=0.3mm] ($(pic cs:A1) + (0.95em,0.5ex)$) -- ($(pic cs:B1) + (-0.65em,0.5ex)$);
  \draw[->, thick, -{Latex[length=2mm]}, line width=0.3mm] (pic cs:A2) -- (pic cs:B2);
\end{tikzpicture}

\end{document}

enter image description here

1 Answer 1

4

With {NiceTabular} of nicematrix and TikZ to draw the arrows by using the Tikz nodes created by nicematrix under the cells, columns and rows of the tabulars.

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

\begin{document}

\begin{NiceTabular}[name=A,hvlines]{cc}
\Block{1-2}{Table 1} \\
Node & Value \\
$\mathbf{A_1}$ & 100 \\
$\mathbf{A_2}$ & 200 \\
\end{NiceTabular}
\hspace{15mm}
\begin{NiceTabular}[name=B,hvlines]{cc}
\Block{1-2}{Table 2} \\
Node* & Value \\
$\mathbf{B_1}$ & 300 \\
$\mathbf{B_2}$ & 400 \\
\end{NiceTabular}
%
\begin{tikzpicture}[remember picture, overlay]
\draw [->] (A-3.5-|A-3) -- (B-2.5-|B-1) ; 
\draw [->] (A-4.5-|A-3) -- (B-4.5-|B-1) ; 
\end{tikzpicture}

\end{document}

Output of the above code

1
  • Perfect solution, @F.Pantigny! Thank you very much indeed!
    – PaulS
    Commented Jun 24 at 19:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .