2

I'd like to draw arrows on a table, to obtain the following picture

enter image description here

So I wrote down this code:

\begin{tabular}{*{6}{|c}|}
   \hline
   \tikzmark{A}{A} & \tikzmark{B}{B} & \tikzmark{C}{C} & \tikzmark{D}{D} & \tikzmark{E}{E} & 
   \tikzmark{F}{F}\\
   \hline
\end{tabular}
\begin{tikzpicture}[remember picture,overlay]
   \draw [->] (pic cs:A) -- (pic cs:F);
\end{tikzpicture}

but it gives me this

enter image description here

instead of something like this (like I expect)

enter image description here

It's like the tikzpicture can't overlay the table, even if I have declared

\begin{tikzpicture}[remember picture,overlay]

How can I solve this issue?

frad
  • 571
  • Did you compile the document twice? – Sergei Golovan Dec 05 '20 at 16:11
  • I did it more than twice lol – frad Dec 05 '20 at 16:12
  • Are you using the tikzmark library or did you include a definition in your preamble? Tikzmark went through a few variations on this site before it stabilised. – Andrew Stacey Dec 05 '20 at 16:32
  • I included the tikz package in the preamble, and then I imported the library \usetikzlibrary(tikzmark) (still in the preamble) – frad Dec 05 '20 at 16:35
  • @frad I've tried your code with a minimal preamble: \documentclass{article}\usepackage{tikz}\usetikzlibrary{tikzmark} and it has produced what I expected to see - an arrow across the cells of the table. I tried with each of pdflatex, xelatex, and lualatex. If you want to send me your full example, my email is on the tikzmark documentation. If you do send it, please also send the logfile and auxfile from your compilation. – Andrew Stacey Dec 06 '20 at 20:11

1 Answers1

3

Use \tikzmarknode. Or a matrix.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,tikzmark}
\begin{document}
\begin{tabular}{*{6}{|c}|}
   \hline
   \tikzmarknode{A}{A} & \tikzmarknode{B}{B} & \tikzmarknode{C}{C} & \tikzmarknode{D}{D} & \tikzmarknode{E}{E} & 
   \tikzmarknode{F}{F}\\
   \hline
\end{tabular}%
\begin{tikzpicture}[remember picture,overlay]
   \draw [-stealth] (A.west) -- (F);
\end{tikzpicture}%
\bigskip

\begin{tikzpicture}[>=stealth] \matrix[matrix of nodes,cells={nodes={draw}},column sep=-\pgflinewidth] (m){A & B & C & D & E & F\}; \draw[->] (m-1-2.north) -- ++ (0,2ex) -| (m-1-4); \draw[->] (m-1-2.south) -- ++ (0,-2ex) -| (m-1-1); \draw[->] (m-1-2.south) -- ++ (0,-1ex) -| (m-1-3); \end{tikzpicture} \end{document}

enter image description here

  • just tried: if I write the code on a new empty document it works. If I do that in my original doc, it still gives me the original error. Is it because of some kind of conflict between packages? – frad Dec 05 '20 at 16:17
  • 1
    @frad Hard to tell without knowing your document. Please try to produce a minimal document that shows the problem. –  Dec 05 '20 at 16:26
  • @frad BTW, for your target picture it might be easier to use a matrix from tikz. Generally tikzmark won't know where the borders of the table are. –  Dec 05 '20 at 16:36
  • I'd like to use the tabular tbh, because I'll need to highlight a couple of rows of a table (like a red rectangle which includes some of the table rows). Is it still possible doing it using the tikz matrix instead of classical tabular? – frad Dec 05 '20 at 16:43
  • 1
    @frad For that one I recommend the nicematrix package, which supports such features for tabulars. –  Dec 05 '20 at 16:49