1

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

3
  • Is it a matrix of nodes? Will every node/.style={font=\ttfamily} as an option to the matrix do? Sep 3, 2012 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 ) Sep 3, 2012 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. Sep 3, 2012 at 20:04

1 Answer 1

3

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.

Code

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

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

\end{document}

Result

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .