\usepackage{tikz} \usepackage{calc} %%% KV Table Macro %%% USAGE: %%% \kvtable{/*function name; e.g. f(x)*/} %%% {{ 0}{ 1}{ 5}{ 4}} %%% {{ 2}{ 3}{ 7}{ 6}} %%% {{10}{11}{15}{14}} %%% {{ 8}{ 9}{13}{12}} %%% { %%% /*Insert draw command for this scope*/ %%% } \def\kvtable#1#2#3#4#5#6{ \begin{tikzpicture} \node at (1,3) {#1}; \draw[|-|] (0.75,-2) -- (0.75,0) node[midway, left]{$x_{3}$}; \draw[|-|] (1.5,-1) -- (1.5,1) node[midway, left]{$x_{1}$}; \draw[|-|] (6,3.25) -- (4,3.25) node[midway, anchor=south]{$x_{2}$}; \draw[|-|] (5,2.5) -- (3,2.5) node[midway, anchor=south]{$x_{0}$}; \draw[step=1cm, gray, very thin] (2,-2) grid (6,2); \node[anchor=south west, scale=.5] at (2,1) {0}; \node[anchor=south west, scale=.5] at (3,1) {1}; \node[anchor=south west, scale=.5] at (2,0) {2}; \node[anchor=south west, scale=.5] at (3,0) {3}; \node[anchor=south west, scale=.5] at (5,1) {4}; \node[anchor=south west, scale=.5] at (4,1) {5}; \node[anchor=south west, scale=.5] at (5,0) {6}; \node[anchor=south west, scale=.5] at (4,0) {7}; \node[anchor=south west, scale=.5] at (2,-2) {8}; \node[anchor=south west, scale=.5] at (3,-2) {9}; \node[anchor=south west, scale=.5] at (2,-1) {10}; \node[anchor=south west, scale=.5] at (3,-1) {11}; \node[anchor=south west, scale=.5] at (5,-2) {12}; \node[anchor=south west, scale=.5] at (4,-2) {13}; \node[anchor=south west, scale=.5] at (5,-1) {14}; \node[anchor=south west, scale=.5] at (4,-1) {15}; \def\kvrow##1##2##3##4##5{ \node[anchor=center, scale=1.25] at (2.5,##5) {##1}; \node[anchor=center, scale=1.25] at (3.5,##5) {##2}; \node[anchor=center, scale=1.25] at (4.5,##5) {##3}; \node[anchor=center, scale=1.25] at (5.5,##5) {##4}; } \kvrow#2{1.5} \kvrow#3{0.5} \kvrow#4{-0.5} \kvrow#5{-1.5} #6 \end{tikzpicture} }