4

I'm creating a table with TikZ overlay arrows to illustrate the data flow between cells. The arrows currently work, but they look somewhat crude and could be improved. I'm looking for suggestions on:

  1. How to make the curved arrows look more fluid and natural
  2. Better positioning strategies for the labeled nodes (A, B, C, D) so they don't overlap with arrows
  3. How to avoid awkward arrow angles and improve the overall visual flow

Here's my MWE:

\documentclass{article} \usepackage[margin=1in]{geometry} \usepackage{amsmath} \usepackage{booktabs} \usepackage{xcolor} \usepackage{lipsum} \usepackage{caption} \usepackage{tikz} \usetikzlibrary{tikzmark} \usepackage[most]{tcolorbox} % Color \definecolor{boxBack}{RGB}{245, 247, 250} \definecolor{darkgrey}{HTML}{464e51} \definecolor{customGray}{HTML}{DDDDDD} \definecolor{customRed}{HTML}{FDE7A9} \definecolor{customOrange}{HTML}{FC8E64} \definecolor{customBlue}{HTML}{B83779} % tcolorbox settings \tcbset{ enhanced, colback=boxBack, colframe=gray!40, boxrule=0.5pt, fonttitle=\bfseries\sffamily, coltitle=black, attach boxed title to top left={xshift=0.5cm, yshift=-3mm}, boxed title style={colback=white, colframe=gray!40, arc=3pt}, top=1em, bottom=1em, left=1em, right=1em } \begin{document} \lipsum[1-3] \begin{tcolorbox}[title=Test] \footnotesize $\quad$ \lipsum[1] \renewcommand{\arraystretch}{1.2} \begin{center} \captionsetup{font=footnotesize,labelfont={color=darkgrey,bf}} \captionof{table}{\textcolor{darkgray}{Example}} \label{tab:shifte} \vspace{-0.5cm} \[ \begin{array}{@{\hspace{1em}}c@{\hspace{2em}}c@{\hspace{3.5em}}c@{\hspace{3.5em}}c@{\hspace{3.5em}}c@{\hspace{2em}}c@{\hspace{1.0em}}} \toprule \text{Day} & \text{$1$} & \text{$2$} & \text{$3$} & \text{$4$} & \text{$\ldots$} \\ \midrule \text{{\fontsize{9}{10}\selectfont ...}} & \text{{E}} & \text{{L}} & \text{{O}} & \text{{E}} & \text{$\ldots$} \\[6pt] \text{$a_{ds}$} & \tikzmarknode{A2}{\text{$(1,0)$}} & \tikzmarknode{A3}{\text{$(0,1)$}} & \tikzmarknode{A4}{\text{$(0,0)$}} & \tikzmarknode{A5}{\text{$(1,0)$}} & \tikzmarknode{A6}{$\ldots$} \\[6pt] \text{$b_{ds}$} & \tikzmarknode{B2}{\text{$(1,0)$}} & \tikzmarknode{B3}{\text{$(1,0)$}} & \tikzmarknode{B4}{\text{$(0,1)$}} & \tikzmarknode{B5}{\text{$(0,1)$}} & \tikzmarknode{B6}{$\ldots$} \\[6pt] \text{$c_{ds}$} & \text{$(0,0)$} & \text{$(0,0)$} & \tikzmarknode{Z1}{\text{$(0,1)$}} & \text{$(0,0)$} & \text{$\ldots$} \\[6pt] \text{$v_{ds}$} & \tikzmarknode{E3}{\text{$(0,0)$}} & \tikzmarknode{E4}{\text{$(0,1)$}} & \text{$(0,0)$} & \tikzmarknode{E5}{\text{$(1,0)$}} & \tikzmarknode{E6}{$\ldots$ } \\ [6pt] \text{$d_{d}$} & \text{$0$} & \text{$1$} & \tikzmarknode{Z12}{\text{$0$}} & \text{$1$} & \text{$\ldots$} \\ \bottomrule \end{array} \] \begin{tikzpicture}[remember picture,overlay] % Fixed the typo here \draw[thick, ->] (-1.94,0.98) -- (-1.32,0.98); \draw[thick, -<] (-1.94,2.02) -- (-1.32,2.02); \draw[thick, -<] (-1.94,2.58) -- (-1.32,2.58); \draw[thick, ->] (-2.44,2.8) -- (-1.32,2.26); \draw[thick, customGray, -] (1.48,1.6) -- (2.56,2.22); \draw[thick, ->] (-0.44,2.8) -- (0.6,1.60); \draw[thick, ->] (1.48,1.6) -- (2.56,2.22); \draw[thick, -] (-1.94,2.58) -- (-1.94,0.98); \fill[customGray] (-2.21,2.65) circle (0.19); \fill[customGray] (2.02,1.91) circle (0.19); \fill[customGray] (0.08,2.16) circle (0.19); \fill[customGray] (-1.94,1.5) circle (0.19); \node[circle,draw,inner sep=1pt,font=\tiny] at (-2.21,2.65) {A}; \node[circle,draw,inner sep=1pt,font=\tiny] at (-1.94,1.5) {B}; \node[circle,draw,inner sep=1pt,font=\tiny] at (0.08,2.16) {C}; \node[circle,draw,inner sep=1pt,font=\tiny] at (2.02,1.91) {D}; \end{tikzpicture} \end{center} \noindent \lipsum[1] \end{tcolorbox} \normalsize \lipsum[2] \end{document} 

I want the arrows to look something like this: enter image description here

2

2 Answers 2

6

Similar to @Sandy G answer, but with use of tabularray and tblr-extras packages and TikZ libraries arrows.meta and ext.paths.ortho. Also from table ode are removed all not used \tikzmarknode. All those measures make table's code more clear and shorter:

\documentclass{article} \usepackage[margin=1in]{geometry} %--------------- show page layout. don't use in a real document! \usepackage{showframe} \renewcommand\ShowFrameLinethickness{0.15pt} \renewcommand*\ShowFrameColor{\color{red}} % \usepackage{lipsum} % for dummy text %---------------------------------------------------------------% \usepackage[skip=0.33\lineskip, font={color=darkgrey,footnotesize}, labelfont=bf]{caption} \usepackage{tabularray, tblr-extras} \UseTblrLibrary{amsmath, booktabs} %\usepackage{tikz} \usepackage[most]{tcolorbox} % Color \definecolor{boxBack}{RGB}{245, 247, 250} \definecolor{darkgrey}{HTML}{464e51} \definecolor{customGray}{HTML}{DDDDDD} %\definecolor{customRed}{HTML}{FDE7A9} %\definecolor{customOrange}{HTML}{FC8E64} %\definecolor{customBlue}{HTML}{B83779} % \usetikzlibrary{arrows.meta, ext.paths.ortho, % defined in the tikz-ext package tikzmark} \tikzset{is/.style = {inner xsep=2pt}} % tcolorbox settings \tcbset{ enhanced, colback=boxBack, colframe=gray!40, boxrule=0.5pt, fonttitle=\bfseries\sffamily, coltitle=black, attach boxed title to top left={xshift=0.5cm, yshift=-3mm}, boxed title style={colback=white, colframe=gray!40, arc=3pt}, top=1em, bottom=1em, left=1em, right=1em } \begin{document} \lipsum[1-2] \begin{tcolorbox}[title=Test] \footnotesize \quad \lipsum[1] \begin{center} \begin{talltblr}[ caption = {Example}, label = {tab:shifte} ]{ width = 0.75\linewidth, colspec = {Q[l,mode=math] *{4}{X[c]}}, row{1,2} = {mode=text}, rowsep = 5pt } \toprule Day & 1 & 2 & 3 & 4 & \ldots \\ \midrule \dots & E & L & O & E & \ldots \\ a_{ds} & \tikzmarknode[is]{A1}{(1,0)} & \tikzmarknode[is]{B1}{(0,1)} & (0,0) & (1,0) & \ldots \\ b_{ds} & (1,0) & \tikzmarknode[is]{A2}{(1,0)} & (0,1) & \tikzmarknode[is]{D2}{(0,1)} & \ldots \\ c_{ds} & (0,0) & (0,0) & \tikzmarknode[is]{C2}{(0,1)} & (0,0) & \ldots \\ v_{ds} & (0,0) & \tikzmarknode[is]{B2}{(0,1)} & (0,0) & (1,0) & \ldots \\ d_{d} & 0 & 1 & 0 & 1 & \ldots \\ \bottomrule \end{talltblr} % \begin{tikzpicture}[remember picture, overlay, every node/.style = {circle, draw, fill=customGray, pos=0.5, inner sep=1pt, font=\tiny}, every path/.style = {draw, semithick, -{Straight Barb[scale=0.8]}, rounded corners}, lr/.style = {draw, semithick, -, sharp corners}, ys/.style = {yshift=#1 mm} ] \draw (A1) -|- ([ys=-1] A2.west) node {A}; \draw (B1) -|- (C2) node {C}; \draw (C2) -|- (D2) node {D}; \draw[lr] (B1) r-lr [lr distance=1mm] coordinate (B1) ([ys=1] A2.west); \draw (B1) r-lr [lr distance=2mm] (B2) node {B}; \end{tikzpicture} \end{center} \lipsum[1] \end{tcolorbox} \lipsum[3] \end{document} 

enter image description here

(red lines indicate page layout)

2
  • Thank you for the answer. Why, however, is the caption "Test" not showing up? Commented 18 hours ago
  • @mingabua, if you tested provided answer, you should observe that caption showup. However, I didn't upload its right result. Now corrected. Commented 12 hours ago
7

There are a few issues with your code.

  • You are creating nodes with tikzmark but not using them. Once the nodes have names, use those names in your \draw commands.
  • Incorporate the nodes into the \draw commands so you don't have to calculate their locations.
  • You are creating many unneeded \tikzmarknodes.
  • Almost never use \text, because it captures the exterior style. Instead use \textup.
  • You are creating an array so math mode is the default. You don't want $...$, which actually leaves math mode, and you definitely don't need \text{$...$}.

I couldn't tell exactly how you wanted the arrows positioned so here is my best guess.

enter image description here

\documentclass{article} \usepackage[margin=1in]{geometry} \usepackage{amsmath} \usepackage{booktabs} \usepackage{xcolor} \usepackage{lipsum} \usepackage{caption} \usepackage{tikz} \usetikzlibrary{tikzmark, calc} \usepackage[most]{tcolorbox} % Color \definecolor{boxBack}{RGB}{245, 247, 250} \definecolor{darkgrey}{HTML}{464e51} \definecolor{customGray}{HTML}{DDDDDD} \definecolor{customRed}{HTML}{FDE7A9} \definecolor{customOrange}{HTML}{FC8E64} \definecolor{customBlue}{HTML}{B83779} % tcolorbox settings \tcbset{ enhanced, colback=boxBack, colframe=gray!40, boxrule=0.5pt, fonttitle=\bfseries\sffamily, coltitle=black, attach boxed title to top left={xshift=0.5cm, yshift=-3mm}, boxed title style={colback=white, colframe=gray!40, arc=3pt}, top=1em, bottom=1em, left=1em, right=1em } \tikzset{ mynode/.style={black, circle, draw, thin, fill=customGray, inner sep=1pt, font=\tiny}, myline/.style={thick, ->, rounded corners} } \begin{document} \lipsum[1-3] \begin{tcolorbox}[title=Test] \footnotesize $\quad$ \lipsum[1] \renewcommand{\arraystretch}{1.2} \begin{center} \captionsetup{font=footnotesize,labelfont={color=darkgrey,bf}} \captionof{table}{\textcolor{darkgray}{Example}} \label{tab:shifte} \vspace{-0.5cm} \[ \begin{array}{@{\hspace{1em}}c@{\hspace{2em}}c@{\hspace{3.5em}}c@{\hspace{3.5em}}c@{\hspace{3.5em}}c@{\hspace{2em}}c@{\hspace{1.0em}}} \toprule \textup{Day} & 1 & 2 & 3 & 4 & \ldots \\ \midrule \ldots & \textup{E} & \textup{L} & 0 & \textup{E} & \ldots \\[6pt] a_{ds} & \tikzmarknode{A2}{(1,0)} & \tikzmarknode{A3}{(0,1)} & (0,0) & (1,0) & \ldots \\[6pt] b_{ds} & (1,0) & \tikzmarknode{B3}{(1,0)} & (0,1) & \tikzmarknode{B5}{(0,1)} & \ldots \\[6pt] c_{ds} & (0,0) & (0,0) & \tikzmarknode{Z1}{(0,1)} & (0,0) & \ldots \\[6pt] v_{ds} & (0,0) & \tikzmarknode{E4}{(0,1)} & (0,0) & (1,0) & \ldots \\ [6pt] d_{d} & 0 & 1 & 0 & 1 & \ldots \\ \bottomrule \end{array} \] \begin{tikzpicture}[remember picture, overlay] \draw[myline] (A2) -|($(A2)!0.5!(B3)$)node[mynode]{A} |- ([yshift=-2pt]B3); \draw[myline] (A3) -| ($(A3)!0.5!(Z1)$)node[mynode]{C} |- (Z1); \draw[myline] (Z1) -| ($(Z1)!0.5!(B5)$)node[mynode]{D} |- (B5); \draw[thick, -] ([yshift=-2pt]A3.west) --++(-.1,0)|- coordinate[pos=.25](M) ([yshift=2pt]B3.west); \draw[thick, ->] (M)--++(-.1,0) |- node[mynode, pos=.25]{B}(E4); \end{tikzpicture} \end{center} \noindent \lipsum[1] \end{tcolorbox} \normalsize \lipsum[2] \end{document} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.