Is Using Tikzmarknode within Tikz Matrix possible?
You do not need tikzmark
here because tikzmark is needed to make a non-node a node, but everything you are playing with here are nodes. EDIT: Fixed the directions of the arrows (big thanks to manoooh) and borrowed column 1/.append style={nodes={text width=15mm}},column 2/.append style={nodes={text width=9mm}}
from Zarkos answer. (However, I disagree with replacing \pgfmathparse{f(1)}\pgfmathprintnumber{\pgfmathresult}
by something using \pgfmathtruncatemacro
because this won't work once you have non-integer results.)
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[declare function={f(\x)=1/ln(2)*ln(\x);}]
\matrix[matrix of math nodes,nodes={align=center,inner sep=3pt,
text height=1.5ex,text depth=.25ex,draw=gray!40,ultra thin},
draw,inner sep=0pt,ampersand replacement=\&,
column 1/.append style={nodes={text width=15mm}},
column 2/.append style={nodes={text width=9mm}} ] (mat1)
at (-5,0){
|[fill=green!40!gray]| x~\text{or}~2^{y} \& |
[fill=green!40!gray]| y \\
1 \& {\pgfmathparse{f(1)}\pgfmathprintnumber{\pgfmathresult}}\\
2 \& {\pgfmathparse{f(2)}\pgfmathprintnumber{\pgfmathresult}}\\
4 \& {\pgfmathparse{f(4)}\pgfmathprintnumber{\pgfmathresult}}\\
8 \& {\pgfmathparse{f(8)}\pgfmathprintnumber{\pgfmathresult}}\\
\frac{1}{2} \& {\pgfmathparse{f(.5)}\pgfmathprintnumber{\pgfmathresult}}\\
\frac{1}{4} \& {\pgfmathparse{f(.25)}\pgfmathprintnumber{\pgfmathresult}}\\
};
\node at ([yshift=-.8cm,xshift=2cm]mat1.south)
[circle,draw,font=\small,inner sep=1pt,label={[red]right:Select $y$}] (1){$1$};
\node at ([yshift=-1.5cm,xshift=.7cm]mat1.south)
[circle,draw,font=\small,inner sep=1pt,label={[red]right:Compute
$x$}] (2){$2$};
\draw[latex-] (mat1-7-1|-mat1.south) |- (2);
\draw[latex-] (mat1-7-2|-mat1.south) |- (1);
\end{tikzpicture}
\end{document}
off-topic (since topic is solved by @marmot answer), but it may be handy at writing of your matrices ...
- with use of
column 1/.append style={nodes={text width=15mm}
(and similarly for column 2) you can remove|[text width=11mm]|
from all cells - with use of
\pgfmathtruncatemacro{\L}{f(<value>)}\L
instead\pgfmathparse{f(.5)}\pgfmathprintnumber{\pgfmathresult}
gives slightly shorter code - for nodes below matrix i would define common style
use of
ampersand replacement=\&
is not necessary\documentclass{article} \usepackage{amsmath} \usepackage{tikz} \usetikzlibrary{matrix} \begin{document} \begin{tikzpicture}[ declare function = {f(\x)=1/ln(2)*ln(\x);}, circ/.style = {circle,draw,font=\small,inner sep=1pt, % <--- label={[red]right:#1}} % <--- ] \matrix[matrix of math nodes, nodes = {align=center,inner sep=3pt, text height=2ex, text depth=1ex, % <--- draw=gray!40,very thin}, draw, inner sep=0pt, column 1/.append style={nodes={text width=15mm}}, % <--- column 2/.append style={nodes={text width=9mm}} % <--- ] (mat1) { |[fill=green!40!gray]| x\text{, or }2^{y} % <--- & |[fill=green!40!gray]| y \\ % <--- 1 & {\pgfmathtruncatemacro{\L}{f(1)}\L} \\ % <--- 2 & {\pgfmathtruncatemacro{\L}{f(2)}\L} \\ 4 & {\pgfmathtruncatemacro{\L}{f(4)}\L} \\ 8 & {\pgfmathtruncatemacro{\L}{f(8)}\L} \\ \frac{1}{2} & {\pgfmathtruncatemacro{\L}{f(0.5)}\L} \\ \frac{1}{4} & {\pgfmathtruncatemacro{\L}{f(0.25)}\L} \\ }; \node at ([yshift=- 8mm] mat1.south east) [circ=Select $y$] (c1) {1}; % <--- \node at ([yshift=-18mm] mat1-7-2) [circ=Compute $x$] (c2) {2}; % <--- \draw[latex-] (mat1-7-2) |- (c1); % <--- \draw[latex-] (mat1-7-1) |- (c2); % <--- \end{tikzpicture} \end{document}
edit:
- corrected direction of arrows
added version with use of original way of calculation of values in the second column, i.e. with
\pgfmathparse{f(1)}\pgfmathprintnumber{\pgfmathresult}
(as noted marmot in his answer, it enable calculation of real values), for which is defined new command\calculation
:\documentclass[tikz, margin=3mm]{standalone} \usetikzlibrary{matrix} \usepackage{amsmath} \begin{tikzpicture}[ declare function = {f(\x)=1/ln(2)*ln(\x);}, circ/.style = {circle,draw,font=\small,inner sep=1pt, % <--- label={[red]right:#1}} % <--- ] \newcommand\calculation[1]{\pgfmathparse{f(#1)}% \pgfmathprintnumber{\pgfmathresult}} % <--- \matrix[matrix of math nodes, nodes = {text height=1.5ex, text depth=0.5ex, % <--- align=center, inner ysep=4pt, draw=gray!40,very thin}, draw, inner sep=0pt, column 1/.append style={nodes={text width=15mm}}, column 2/.append style={nodes={text width=11mm}}, row 1/.style = {nodes={fill=green!40!gray}} % <--- ] (mat1) { x\text{, or }2^{y} % <--- & y \\ % <--- 1 & {\calculation{1}} \\ % <--- 2 & {\calculation{2}} \\ 4 & {\calculation{4}} \\ 8 & {\calculation{8}} \\ \frac{1}{2} & {\calculation{0.5}} \\ \frac{1}{4} & {\calculation{0.25}} \\ }; \node at ([yshift=- 8mm] mat1.south east) [circ=Select $y$] (c1) {1}; % <--- \node at ([yshift=-18mm] mat1-7-2) [circ=Compute $x$] (c2) {2}; % <--- \draw[latex-] (mat1-7-2) |- (c1); % <--- \draw[latex-] (mat1-7-1) |- (c2); % <--- \end{tikzpicture} \end{document}
the result is the same as above.