I have the following Tikzpicture which creates a table. My question is, the numbers in the upper left corners, is it posible to asign a variable with a matrix of values.
Using pseudo-code: Something like
variable={-3,4,3,M; 0,-2,0,0; -1,-1,-3,M; 0,M,0,0} so that the values can be accessed using \variable{1,1}, for instance.
The line \path (m-1-1) node {-3}; would be some like \path (m-1-1) node {\variable{1,1}};
\documentclass[border=1cm]{standalone}
\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,fit,calc, automata}
\begin{document}
\begin{tikzpicture}
\matrix(m) [matrix of math nodes, nodes in empty cells, nodes={minimum size=1cm, outer sep=0pt, text height=1.5ex, text depth=.25ex}]
{
& & & & & & & & & & & \
& & & & & & & & & & & \
& & & & & & & & & & & \
& & & & & & & & & & & \
& & & & & & & & & & & \
& & & & & & & & & & & \
& & & & & & & & & & & \
& & & & & & & & & & & \
& & & & & & & & & & & \
& & & & & & & & & & & \
& & & & & & & & & & & \
& & & & & & & & & & & \
};
% Costos
% Primera fila
\path (m-1-1) node {-3};
\path (m-1-4) node {4};
\path (m-1-7) node {3};
\path (m-1-10) node {M};
% Segunda fila
\path (m-4-1) node {0};
\path (m-4-4) node {-2};
\path (m-4-7) node {0};
\path (m-4-10) node {0};
\path (m-4-12) node {(-)};
% Tercera fila
\path (m-7-1) node {-1};
\path (m-7-4) node {-1};
\path (m-7-7) node {-3};
\path (m-7-10) node {M};
% Cuarta fila
\path (m-10-1) node {0};
\path (m-10-3) node {(-)};
\path (m-10-4) node {M};
\path (m-10-7) node {0};
\path (m-10-10) node {0};
% Limites superiores y inferiores
% Segunda fila
\path (m-4-3) node {8};
\path (m-4-6) node {4};
% Tercera fila
\path (m-7-6) node {5};
\path (m-7-9) node {4};
\draw (m-1-1.north west) rectangle (m-12-12.south east);
% Lineas horizontales
\foreach \i in {3,6,9} {
\draw (m-\i-1.south west) -- (m-\i-12.south east);
}
% Lineas verticales
\foreach \j in {3,6,9} {
\draw (m-1-\j.north east) -- (m-12-\j.south east);
}
\foreach \k in {4-3,4-6,
7-6,7-9} {
\draw (m-\k.south west) rectangle (m-\k.north east);
}
\end{tikzpicture}
\end{document}



store matrixin value-keys which can then simply received later. If the number of items per row is known beforehand (e.g. 4) both approaches can be transformed into something that only takes one list:-3, 4, 3, M, 0, -2, …. – Qrrbrbirlbel Apr 22 '23 at 22:48