This is a small matrix with 5x3 nodes. My true matrix is much bigger, and I preferred to give a number to each cell (from 1 to 15 - yes, I know 0 to 14 would be easier). I already numbered the cells with a foreach to illustrate the numbering.
What I want is to color some horizontal separation lines, giving the number of the cell at the left and the number of the cell at the right. It works perfectly when the matrix coordinates are given with static numbers (for instance, the red line between 7 and 9). It doesn't work if I try to dynamically generate the cell numbers in a foreach loop (for instance the blue line between 1 and 3). Apparently, the offset (north, south, east...) is ignored. As you can imagine, I made a lot of variants before asking for help here.
Would you have any idea where would be my mistake?
Thanks in advance.
This is my MWE
\documentclass[a4paper, 11pt]{report}
% --- DOCUMENT
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{caption}
\begin{document}
\begin{figure}[!h]\centering
\usetikzlibrary{matrix,calc}
\begin{tikzpicture}[ampersand replacement=\&]
\tikzset{
table nodes/.style={rectangle, draw, align=center, minimum height=5mm,
text depth=0.5ex,text height=1ex,inner xsep=0pt,outer sep=0pt
},
table/.style={matrix of nodes, row sep=-\pgflinewidth, column sep=-\pgflinewidth,
nodes={table nodes},
execute at empty cell={\node[draw=none]{}; }
}
}
\matrix at (0,0) [table,text width=5mm,name=MX] {%
\ \&\ \&\ \\\ \&\ \&\ \\\ \&\ \&\ \\\ \&\ \&\ \\\ \&\ \&\ \\};
\foreach \i [evaluate={\r=int((\i-1)/3+1); \c={int(mod(\i-1,3)+1)} }] in {1,...,15} {
\node at ($(MX-\r-\c)$) {\footnotesize\i};
}
\foreach \b/\e [evaluate={\r=int((\b-1)/3+1); \c={int(mod(\b-1,3)+1)}; \d={int(mod(\e-1,3)+1)} }] in {1/3} { %
\draw[red,semithick] ($(MX-\r-\c)$) circle(2pt); <--- THIS WORKS
\draw[blue,semithick] ($(MX-\r-\c)$.south) -- ($(MX-\r-\d)$.south); <--- THIS DOESN'T WORK
%\coordinate (N) at ($(MX-\r-\c)$);
%\draw[blue,semithick] (N.south) circle(2pt); <--- THIS DOESN'T WORK
%\draw[blue,semithick] (N.south) circle(2pt); <--- THIS DOESN'T WORK
}
\draw[red,semithick] (MX-3-1.south west) -- (MX-3-3.south east); % <--- THIS WORKS
% useasboundingbox
\useasboundingbox[blue] ($(MX-1-1.north west)+(135:10pt)$) rectangle ($(MX-5-3.south east)+(315:10pt)$);
\end{tikzpicture}
\caption{Matrix example}
\end{figure}
\end{document}
\draw[blue,semithick] (MX-\r-\c.south) -- (MX-\r-\d.south);
?