I have several questions about a table I have created for an exercise.
- The numbers that are inside the circles. How can they be centred?
- I would like to shift the purple polygon, a little to the left and a little down.
- Is there a more easy way to do the table. Keep in mind that I used Tikz in order to draw on top of the table and I also need to do many iterations.
Many thanks in advance!
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,fit,automata}
\usepackage{adjustbox}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{adjustbox}{max totalsize={.9\textwidth}{.9\textheight},center}
\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}]
{
1 & + & 2 & & 3 & & 5 & & 0 & - \\
&\textcolor{blue}{0}& &\textcolor{blue}{1}& &\textcolor{blue}{2}& &\textcolor{blue}{4}& &\textcolor{blue}{0}\\
0 & - & 1 & + & 5 & & 3 & & 3 & \\
&\textcolor{blue}{0}& &\textcolor{blue}{1}& &\textcolor{blue}{5}& &\textcolor{blue}{3}& &\textcolor{blue}{4}\\
3 & & 0 & & 4 & & 0 & & 3 & \\
&\textcolor{blue}{3}& &\textcolor{blue}{0}& &\textcolor{blue}{4}& &\textcolor{blue}{0}& &\textcolor{blue}{4}\\
5 & & 7 & & 0 & & 0 & & 2 & \\
&\textcolor{blue}{5}& &\textcolor{blue}{7}& &\textcolor{blue}{0}& &\textcolor{blue}{0}& &\textcolor{blue}{3}\\
3 & & 1 & - & 4 & & 5 & & 0 & + \\
&\textcolor{blue}{3}& &\textcolor{blue}{0}& &\textcolor{blue}{3}& &\textcolor{blue}{5}& &\textcolor{blue}{0}\\
};
\draw (m-1-1.north west) rectangle (m-10-10.south east);
% Lineas horizontales
\foreach \i in {2,4,6,8,10} {
\draw (m-\i-1.south west) -- (m-\i-10.south east);
}
% Lineas verticales
\foreach \j in {2,4,6,8,10} {
\draw (m-1-\j.north east) -- (m-10-\j.south east);
}
% Solucion
\node[draw=blue,circle,fit=(m-1-9)(m-2-10),inner sep = -19pt] {1};
\node[draw=blue,circle,fit=(m-3-1)(m-4-2),inner sep = -19pt] {1};
\node[draw=blue,circle,fit=(m-5-7)(m-6-8),inner sep = -19pt] {1};
\node[draw=blue,circle,fit=(m-7-5)(m-8-6),inner sep = -19pt] {1};
\node[draw=blue,circle,fit=(m-9-3)(m-10-4),inner sep = -19pt] {1};
\node[draw=blue,circle,fit=(m-1-1)(m-2-2),inner sep = -19pt] {0};
\node[draw=blue,circle,fit=(m-5-3)(m-6-4),inner sep = -19pt] {0};
\node[draw=blue,circle,fit=(m-7-7)(m-8-8),inner sep = -19pt] {0};
\node[draw=blue,circle,fit=(m-9-9)(m-10-10),inner sep = -19pt] {0};
% dual ui
\node [font=\color{red}] at (6,4) {0};
\node [font=\color{red}] at (6,2) {-1};
\node [font=\color{red}] at (6,0) {-1};
\node [font=\color{red}] at (6,-2) {-1};
\node [font=\color{red}] at (6,-4) {0};
% dual vj
\node [font=\color{red}] at (-4,-6) {1};
\node [font=\color{red}] at (-2,-6) {1};
\node [font=\color{red}] at (0,-6) {1};
\node [font=\color{red}] at (2,-6) {1};
\node [font=\color{red}] at (4,-6) {0};
% poligono
\draw [purple, dashed,very thick](m-2-1.north) -- (m-2-9.north) -- (m-10-9.north) -- (m-10-3.north) -- (m-4-3.north) -- (m-4-1.north) -- (m-2-1.north);
\end{tikzpicture}
\end{adjustbox}
\end{document}