I am a beginner to Latex and Tikz. I'm facing the following problem: I want to create a table with hex values from 00 to FF in tikz using for each. However, is there a way to specify hex values with other variables? Currently, the example in TikZ manual uses the existing variables in the loop like this:

\foreach \x in {0,1,2,3}
\foreach \y in {0,1,2,3}
\draw (\x,\y) circle (0.2cm);
\fill (\x,\y) circle (0.1cm);

It uses the x and y variables, but how do I specify my own variable, with hex values for each node?

  • You should look up how to use counters, and then perhaps use the moreenum package to convert counter values to hex. – Seamus Dec 11 '16 at 16:53

I'd suggest keeping yourself and TeX in decimal, and converting to hex as needed for presentation:

enter image description here

\usepackage{fmtcount} % for hex conversion



\foreach \row in {0, ..., 15}
  \foreach \col in {0, ..., 15}
    \node[xshift=\col cm, yshift=-\row em]

  • 2
    pgfmath knows about hex numbers hex(x) and Hex(x) can do the conversion on integers – percusse Dec 11 '16 at 17:27
  • Thanks for your answer. When I add draw to the \node, the table is not rendered properly. Could we use grid for a proper table? I cannot make the borders overlap correctly with xshift and yshift. – Tu Do Dec 11 '16 at 17:55
  • Not knowing what you want to draw, I can't say. The usual tabular designs tend to not add grids or excess lines. – Mike Renfro Dec 12 '16 at 3:48
  • Well, what if I want to draw something similar to the periodic table? Those tables tend to have grid, but width big square boxes . – Tu Do Dec 12 '16 at 5:14
  • At 16x16 on a normal portrait sheet of paper and typical font sizes, those boxes won't be large, but I'll see what I can come up with if someone doesn't beat me to it. – Mike Renfro Dec 12 '16 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.