[Solved] Text alignment in Tikz nodes with linebreaks just wont work

Felix Asks: Text alignment in Tikz nodes with linebreaks just wont work
I am really sorry to bother you guys with this standard sounding question, but I am desperate and can’t solve it. I’ve read every thread on tex.sx about this that I could find and yet, I can’t get this under control. So here is the thing:

I want to place a two lines text inside each node in a grid and want them to be centered. Now I am aware of this among other threads. E.g. the most natural solution would be to use align=center in combination with linebreaks \ inside the node text brackets.

Picture and MWE below. As you can see, the letters are not centered, while the numbering is. I tried:

  • align + \
  • text width, alone and in combination with the above
  • tabular environment inside the node text brackets
  • removing the scriptsize parameter I use As you can see, I use nested for loops to create a grid that counts up in a serpentine formation. Certain groups of indices (predefined externally) receiver certain letters, I achieve this with the defined command mylabel. Got the idea for this from my question earlier. However, I just cant get the letters to align centered with the numbers in the line below. Can anybody help?


enter image description here

Code:
documentclass{standalone}
usepackage{tikz}

%=================================
defgroupC{{2,11,13,22,24,33,35,44,46,55,57,66,68,77,79,88}}
defgroupA{{3,4,5,6,7,8,9,10,14,15,16,17,18,19,20,21,25,26,27,28,29,30,31,32,36,37,38,39,40,41,42,43,47,48,49,50,51,52,53,54,58,59,60,61,62,63,64,65,69,70,71,72,73,74,75,76,80,81,82,83,84,85,86,87}}
defgroupH{{12,23,34,45,56,67,78}}
defgroupO{{89}}

newcommand{mylabel}[1]
{%
  pgfmathtruncatemacro{num}{#1}
  foreachc in {0,...,15}
  {%
    pgfmathtruncatemacro{temp}{groupC[c]}%
    ifnum num = temp scriptsize Cfi
  }
  foreacha in {0,...,63}
  {%
    pgfmathtruncatemacro{temp}{groupA[a]}%
    ifnum num = temp scriptsize Afi
  }  
  foreachh in {0,...,6}
  {%
    pgfmathtruncatemacro{temp}{groupH[h]}%
    ifnum num = temp scriptsize Hfi
  }
  ifnum num = 89 scriptsize Ofi 
}

begin{document}
begin{tikzpicture}[node distance=1cm]

foreach i in {0,...,7}
  foreach j in {0,...,10}
    {pgfmathtruncatemacro{label}{11*i+j+2}
    {pgfmathsetmacro{x}{1*j*(-1)^(i) + 5*(-1)^(i+1)}
    node (elabel) [rectangle, draw=black, minimum width=1cm, align=center] at (x,-1*i) {
    mylabel{label}\[-5pt]
    scriptsize(label)
    };
    }}

end{tikzpicture}
end{document}

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.