TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a tikz matrix

 row1 & a  b  c  & d  e  f \\
 row2 & 1  12 16 & 34 2  55 \\

and I need to keep the spacing correct(basically use a monospaced font) for correctly alignment between rows.

I can't make each letter into it's own column because it will mess up the total matrix(which is more complex than the example above). Some columns will not have to be spaced like this. I could possibly make the whole matrix monospaced though if it will preserve spacing?

I've tried \verbatim but I get errors. The

share|improve this question
Is it a matrix of nodes? Will every node/.style={font=\ttfamily} as an option to the matrix do? – Torbjørn T. Sep 3 '12 at 19:38
@TorbjørnT. This doesn't seem to preserve to more than one space. (e.g., it keeps a b c aligned with 1 2 3 but not a b c with 11 22 33 ) – AbstractDissonance Sep 3 '12 at 19:49
Indeed, it doesn't, as it's not verbatim. Plain \verb|1 2 3| works, but I don't know how to set that for all cells. – Torbjørn T. Sep 3 '12 at 20:04
up vote 3 down vote accepted

Here's a solution. It uses typewriter font to ensure that all characters have the same width. Furthermore instead of normal spaces () you can used protected spaces (~). Without options, the cells are aligned centered, you need to align them left by specifying right (e.g. make them starting left and growing to the right). The draw option was only set to illustrate the dimension of the individual cells.




\matrix [matrix of nodes,nodes={font=\ttfamily,draw,right}]
{   row1 & a~~b~~c  & d~~e~f \\
    row2 & 1~~12~16 & 34~2~55 \\



enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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