# Labelings with Tikzmark

I need some help placing labels appropriately.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{colortbl} %%% ALLOWS COLORING OF CELL IN TABULAR ENVIRONMENT
\usepackage{amsmath}
\usepackage{hhline}
\begin{document}
\begin{center}
\begin{tabular}{|cc|p{1in}|cc|p{1in}|cc|} \hhline{--~--~--}
\multicolumn{2}{|c|}{\tikzmarknode{A}{\cellcolor{green!50!white}U.S.}}
&&\multicolumn{2}{c|}{\tikzmarknode{B}
{}\cellcolor{green!50!white}France}&&\multicolumn{2}{c|}
{\cellcolor{green!50!white}Japan} \\ [5pt] \hhline{--~--~--}
\multicolumn{2}{|c|}{$8$} &&\multicolumn{2}{c|}{$41\frac{1} {3}$}&&\multicolumn{2}{c|}{$260$} \\ [5pt]%\hhline{--~--~--}
\multicolumn{2}{|c|}{$9$} &&\multicolumn{2}{c|}{$42\frac{2} {3}$}&&\multicolumn{2}{c|}{$270$} \\ [5pt]%\hhline{--~--~--}
\multicolumn{2}{|c|}{$10$} &&\multicolumn{2}{c|}{$44$}&&\multicolumn{2}{c|}
{$280$} \\ [5pt]%\hhline{--~--~--}
\multicolumn{2}{|c|}{$11$} &&\multicolumn{2}{c|}{$45\frac{1} {3}$}&&\multicolumn{2}{c|}{$290$} \\ [5pt]%\hhline{--~--~--}
\multicolumn{2}{|c|}{$11\frac{1}{2}$} &&\multicolumn{2}{c|}
{$46$}&&\multicolumn{2}{c|}{$295$} \\ [5pt] \hhline{--~--~--}
\end{tabular}
\end{center}

\begin{tikzpicture}[overlay,remember picture]
\draw[red,-latex] ([yshift=5pt,xshift=-5pt]A.north) -- ++  (0pt,24pt)
coordinate (aux)  -|  ([yshift=9pt,xshift=7pt]B.north) ;
\end{tikzpicture}
\end{document}


This outputs:

The labels I am trying to make:

to me it seems to be more simple to draw all as tikz picture:

\documentclass[tikz, margin=3.14192]{standalone}
\usetikzlibrary{arrows.meta, matrix}
\usepackage{nccmath}   % for used \mfrac

\begin{document}
\begin{tikzpicture}[
FIT/.style = {draw, inner sep=0pt, outer sep=0pt, fit=#1},
arr/.style = {red, semithick, -{Triangle[length=0pt 4,width=0pt 4]},
shorten >=1mm, shorten <=1mm }
]
\matrix (m) [matrix of math nodes,
nodes={minimum width=3em, minimum height=4.5ex,
inner ysep=1pt, inner xsep=2pt, anchor=center},
column sep=22mm,
row sep =-\pgflinewidth,
row 1/.style = {nodes={draw, fill=olive!25}}
]
{
\text{US}       &   \text{France}   &   \text{Japan}    \\
8               &   41\mfrac{1}{3}  &   260             \\
9               &   42\mfrac{2}{3}  &   270             \\
10              &   44              &   280             \\
11              &   45\mfrac{1}{3}  &   290             \\
11\mfrac{1}{2}  &   46              &   295             \\
};
\draw[arr]  (m-1-1.north) -- ++  (0pt,24pt) -|
node[pos=0.25,below] {$g(x)=\dfrac{4x+92}{3}$}
node[pos=0.25,text=cyan, above] {$g$}
([ xshift=-1ex] m-1-2.north) ;
\draw[arr]  ([xshift=1ex]m-1-2.north) -- ++  (0pt,24pt) -|
node[pos=0.25,below] {$f(x)=\dfrac{15x-100}{2}$}
node[pos=0.25,text=cyan, above] {$f$}
(m-1-3) ;
\draw[arr]  (m-6-1.south) -- ++  (0pt,-24pt) -|
node[pos=0.25,below] {$h(x)=?$}
node[pos=0.25,text=cyan, above] {$h$}
(m-6-3) ;
\draw   (m-1-1.south west) |- (m-6-1.south east) -- (m-1-1.south east)
(m-1-2.south west) |- (m-6-2.south -| m-1-2.east) -- (m-1-2.south east)
(m-1-3.south west) |- (m-6-3.south east) -- (m-1-3.south east);
\end{tikzpicture}
\end{document}


which gives:

in code are used two tikz libraries: arrows.meta for arrowsandmatrix by which is replaced your table.

addendum: off-topic, however result might be interesting :-). with use of the \nicefrac from the packages of the same name, the image become more compact and for my taste nicer:

\documentclass[tikz, margin=3.14192]{standalone}
\usetikzlibrary{arrows.meta, matrix}
\usepackage{amsmath, nicefrac}   % for nice frac

\begin{document}
\begin{tikzpicture}[
FIT/.style = {draw, inner sep=0pt, outer sep=0pt, fit=#1},
arr/.style = {red, semithick, -{Triangle[length=0pt 4,width=0pt 4]},
shorten >=1mm, shorten <=1mm }
]
\matrix (m) [matrix of math nodes,
nodes={minimum width=3em, minimum height=3.5ex,
inner ysep=1pt, inner xsep=2pt, anchor=center},
column sep=22mm,
row sep =-\pgflinewidth,
row 1/.style = {nodes={draw, fill=olive!25}}
]
{
\text{US}           &   \text{France}       &   \text{Japan}    \\
8                   &   41\nicefrac{1}{3}   &   260             \\
9                   &   42\nicefrac{2}{3}   &   270             \\
10                  &   44                  &   280             \\
11                  &   45\nicefrac{1}{3}   &   290             \\
11\nicefrac{1}{2}   &   46                  &   295             \\
};
\draw[arr]  (m-1-1.north) -- ++  (0pt,24pt) -|
node[pos=0.25,below] {$g(x)=\dfrac{4x+92}{3}$}
node[pos=0.25,text=cyan, above] {$g$}
([ xshift=-1ex] m-1-2.north) ;
\draw[arr]  ([xshift=1ex]m-1-2.north) -- ++  (0pt,24pt) -|
node[pos=0.25,below] {$f(x)=\dfrac{15x-100}{2}$}
node[pos=0.25,text=cyan, above] {$f$}
(m-1-3) ;
\draw[arr]  (m-6-1.south) -- ++  (0pt,-24pt) -|
node[pos=0.25,below] {$h(x)=?$}
node[pos=0.25,text=cyan, above] {$h$}
(m-6-3) ;
\draw   (m-1-1.south west) |- (m-6-1.south east) -- (m-1-1.south east)
(m-1-2.south west) |- (m-6-2.south -| m-1-2.east) -- (m-1-2.south east)
(m-1-3.south west) |- (m-6-3.south east) -- (m-1-3.south east);
\end{tikzpicture}
\end{document}


• you answered my question plus showed the more advanced way for me. I was aware of this method but did not know how to start the program. Thanks for giving me something to study from! – MathScholar Dec 14 '18 at 21:53
• @MathScholar, you are welcome. just now i observe that i didn't upload the last code version. now is corrected. happy texing! – Zarko Dec 14 '18 at 21:56

tikzmark with a normal tabular still creates a decent result. The table entries are simplified with tabular headers >{$}c<{$} so that mathmode becomes the default. Note that when drawing your arrows, start from the same node, (f), to have the lines at the same height. Also, I have borrowed the nice olive!25 from @Zarko.

\documentclass{article}
\usepackage{colortbl,amsmath,tikz,hhline}
\usetikzlibrary{tikzmark}
\begin{document}

\begin{tabular}[t]{|>{$}c<{$}|}
\hhline{-} \tikzmarknode{u}{\cellcolor{olive!25}\text{U.S.}}   \\ \hhline{-} 8 \\ 9 \\ 10 \\ 11 \\ \tikzmarknode{bl}{11\frac12} \\ \hline
\end{tabular}\hspace{5em}
\begin{tabular}[t]{|>{$}c<{$}|}
\hhline{-} \tikzmarknode{f}{\cellcolor{olive!25}\text{France}} \\ \hhline{-} 8 \\ 9 \\ 10 \\ 11 \\ 11\frac12 \\ \hline
\end{tabular}\hspace{5em}
\begin{tabular}[t]{|>{$}c<{$}|}
\hhline{-} \tikzmarknode{j}{\cellcolor{olive!25}\text{Japan}}  \\ \hhline{-} 8 \\ 9 \\ 10 \\ 11 \\ \tikzmarknode{br}{11\frac12} \\ \hline
\end{tabular}

\begin{tikzpicture}[remember picture, overlay, shorten >=.5em, shorten <=.5em]
\draw[<-] (f.120) -- ++(0,3em) -| node[above,pos=.25]{$g$}node[below,pos=.25]{$g(x)=\dfrac{4x+92}{3}$}(u);
\draw[->] (f.60) -- ++(0,3em) -| node[above,pos=.25]{$f$}node[below,pos=.25]{$f(x)=\dfrac{15x-100}{2}$}(j);
\draw[->] (bl) -- ++(0,-3em) -| node[above,pos=.25]{$h$}node[below,pos=.25]{$h(x)=?$}(br);
\end{tikzpicture}

\end{document}


• thank you for this! I added it to my collection. I used my original "tabular program" as well but needed some syntax from Zarko's and your program to answer the question. – MathScholar Dec 14 '18 at 23:10

### Update: Added a second solution still without a single piece of the tikzmark package in it:-)

It uses the shapes.multipart library which allows to create rectangles composed of two parts separated by the macro \nodepart{two}

This allows the different parts of the rectangle to be colored separately. For that, I wrote the table style.

table/.style={rectangle split,rectangle split parts=2,
rectangle split part fill={green!50,white}}


I added two default values to the bridge style.

bridge/.default={north}{11mm},


The result is identical to the previous solution, the complete code is:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,quotes,shapes.multipart}
\usepackage{colortbl}
\usepackage{amsmath}
\renewcommand{\arraystretch}{1.5}
\tikzset{bridge/.style 2 args= {->,red,near start,auto,to path={([xshift=4pt]\tikztostart.#1)-- ++(0,#2) -| ([xshift=-4pt]\tikztotarget)\tikztonodes}},
bridge/.default={north}{11mm},
table/.style={rectangle split,rectangle split parts=2,
rectangle split part fill={green!50,white}}
}
\begin{document}
\begin{tikzpicture}[node distance=2cm,
]
\node[draw,table](US){
U.S.
\nodepart{two}
\begin{tabular}{c}
8\\
9\\
10\\
11\\
$11\frac{1}{2}$\\
\end{tabular}
};

\node[draw,table,right=of US](France){
France\\
\nodepart{two}
\begin{tabular}{c}
$41\frac{1} {3}$\\
$42\frac{2} {3}$\\
44\\
$45\frac{1} {3}$\\
46\\
\end{tabular}
};

\node[draw,table,right=of France](Japan){
Japan\\
\nodepart{two}
\begin{tabular}{c}
260\\
270\\
280\\
290\\
295\\
\end{tabular}
};

\draw[bridge] (US)to ["g",text=blue] node[swap,text=red] {$g(x)=\dfrac{4x+92}{3}$}(France);
\draw[bridge] (France) to ["f",text=blue] node[swap,text=red] {$g(x)=\dfrac{15x-100}{2}$}(Japan);
\draw[bridge={south}{-5mm}] (US)to ["h",text=blue]node[swap,text=red]{$h(x)=?$}(Japan);
\end{tikzpicture}

\end{document}


### Old answer: Just for fun, here is a pure TikZ solution.

And without a single piece of the excellent tikzmark package in it:-)

It is possible to place a tabular environment in a node with TikZ (see page 223 of manual 3.0.1a). Once this is done, each node is connected in the classic way.

Here, for the pleasure of manipulating TikZ styles with the operation to path, I wrote a bridge style of 2 arguments:

• the first one is the anchor to which the arrow start is attached,
• the second one is the height of the bridge.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,quotes}
\usepackage{colortbl}
\usepackage{amsmath}
\renewcommand{\arraystretch}{1.5}
\tikzset{bridge/.style 2 args= {->,red,near start,auto,to path={([xshift=4pt]\tikztostart.#1)-- ++(0,#2) -| ([xshift=-4pt]\tikztotarget)\tikztonodes}},
}
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node[](US){
\begin{tabular}{|c|}
\hline
\cellcolor{green!50!white}U.S.\\
\hline
8\\
9\\
10\\
11\\
$11\frac{1}{2}$\\
\hline
\end{tabular}
};

\node[right=of US](France){
\begin{tabular}{|c|}
\hline
\cellcolor{green!50!white}France\\
\hline
$41\frac{1} {3}$\\
$42\frac{2} {3}$\\
44\\
$45\frac{1} {3}$\\
46\\
\hline
\end{tabular}
};

\node[right=of France](Japan){
\begin{tabular}{|c|}
\hline
\cellcolor{green!50!white}Japan\\
\hline
260\\
270\\
280\\
290\\
295\\
\hline
\end{tabular}
};

\draw[bridge={north}{11mm}] (US)to ["g",text=blue] node[swap,text=red] {$g(x)=\dfrac{4x+92}{3}$}(France);
\draw[bridge={north}{11mm}] (France) to ["f",text=blue] node[swap,text=red] {$g(x)=\dfrac{15x-100}{2}$}(Japan);
\draw[bridge={south}{-5mm}] (US)to ["h",text=blue]node[swap,text=red]{$h(x)=?$}(Japan);
\end{tikzpicture}

\end{document}
`

Translated with www.DeepL.com/Translator

• thank you for this. I added to my collection of answers to this question. It nice to have several ways to accomplish the same task. It helps in learning the programming language! – MathScholar Dec 16 '18 at 18:49