2

I'm trying to use TikZ to reimplement a diagram I did using PSTricks, and I think I must have the wrong mental model. Here's how I'm tackling the problem:

  • The overall diagram layout is made with a tabular environment.

  • The typical cell within the tabular layout needs to be a TikZ node, so I can draw curves that point to it.

  • Sometimes a cell contains a bullet, which needs to be the origin of a curve drawn to the edge of another cell.

  • Some truly exciting cells stack text on top of another little diagram which itself contains two bullets, each of which originates an arrow that is drawn to another node.

Here's how I've tried to solve the problem:

  1. Each cell within the tabular has its own \begin{tikzpicture}...\end{tikzpicture, with the remember picture option.

  2. Each cell is a node that I can point to.

  3. If the contents of a cell is just text, then it is just text.

  4. If the contents of a cell is more complicated, I put another \begin{tikzpicture}...\end{tikzpicture} in the contents of the node.

  5. Each curve, more or less, is in its own \begin{tikzpicture}...\end{tikzpicture}.

I'm thrashing around getting this to work, mostly by throwing overlay in more or less at random. But I don't have a mental model. What I've learned from searching TeX.se and elsewhere is "don't do that." What should I be doing?

What should I read in order to develop a suitable mental model for specifying diagrams within TeX within diagrams within TeX? And so on?

  • One option is to make each cell content a \tikzmarknode, which requires the tikzmark library. Then the picture in which you draw the connections needs to have the keys remember picture,overlay. (You may use collcell to automatize that.) Another way is to use a TikZ matrix of nodes, which requires the matrix library, to do the whole table in one tikzpicture. – user194703 Dec 18 '19 at 1:51
  • I second making the whole diagram a single tikzpicture and using a matrix to control the layout. – Andrew Stacey Dec 18 '19 at 6:45
5

Here is an example using tikzmark. The picture in which you draw the connections needs to have the keys remember picture,overlay.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{bullet/.style={circle,inner sep=0.2ex,fill}}
\begin{document}
\begin{table}[htb]
% note that the table borders are just for illustration
% this works with bookmarks, too
\centering
\begin{tabular}{|l|c|l|}
\hline
\tikzmarknode{bla}{bla} & \tikzmarknode{bla2}{bla} & \tikzmarknode{blub}{blub}\\
\hline
\tikzmarknode[bullet]{b1}{} &  
\begin{tikzpicture}[remember picture,baseline={(0,0)}]
 \draw[thick,blue] plot[variable=\x,domain=0:3] (\x,{sin(\x*120)});
 \path (0.5,1.2) node[bullet] (b3){} (1.5,1.2) node[bullet] (b4){}
 (0,1.4) (0,-1.2);
\end{tikzpicture}
& \tikzmarknode[bullet]{b2}{} \\
\hline
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
 \draw[red,-stealth] (bla) to[bend left] (bla2);
 \draw[red,-stealth] (bla2) to[bend left] (blub);
 \draw[red,-stealth] (bla) to[bend left] (b1);
 \draw[red,-stealth] (bla) to[bend left] (b3);
 \draw[red,-stealth] (blub) to[bend left] (b2);
 \draw[red,-stealth] (blub) to[bend left] (b4);
\end{tikzpicture}
\caption{A table with \texttt{\textbackslash tikzmarknode}s,
\texttt{tikzpicture}s and Ti\emph{k}Z annotations.}
\end{table}

\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.