3

I want to create a diagram with a couple tables and arrows/braces to describe what changes between the table as different functions are applied to it. However, when creating a table with matrix of nodes, the node sizes are different and it makes the entire table look ugly.

Here is my code:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\tikzstyle{every node}=[draw, scale=0.75, inner sep=0mm]
\tikzstyle{matrix of nodes}=[
inner sep = 0mm,
execute at begin cell=\node\bgroup,
execute at end cell=\egroup;%
]
\tikzstyle{column 1} = [nodes={fill=blue!20}]
\matrix [matrix of nodes, nodes={draw=none}, minimum size = 1.25em]
{
A & 1 & 2 \\
B & 3 & 4 \\
C & 5 & 6 \\
};

\end{tikzpicture}
\end{document}

The end result is this:

enter image description here

A, B, and C are clearly a bit taller than the numbers. I tried messing with the font sizes and minimum sizes, but the discrepancy is still there. Is there any way to make it such that they are the same size?

1
  • Can you post the code that produces the picture that you've posted? It might not be the node size but how you are rendering them. That difference looks awfully like the line width to me. May 24, 2022 at 5:49

3 Answers 3

5

I think this is nothing related to the node. This is how they will be type depends on the font. If you really want ro make them in same height. You can manfully scale the number a little bit. However I don't think this is necessary.

enter image description here

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\tikzstyle{every node}=[draw, scale=0.75, inner sep=0mm]
\tikzstyle{matrix of nodes}=[
inner sep =0mm,
execute at begin cell=\node\bgroup,
execute at end cell=\egroup;%
]
\tikzstyle{column 1} = [nodes={fill=blue!20}]
\matrix [matrix of nodes, nodes={draw=none}, minimum size = 1.25em]
{%
A1 & A\scalebox{1.07}{1} & 2 \\
B3 & B\scalebox{1.03}{3} & 4 \\
C5 & C\scalebox{1.05}{5} & 6 \\
};
\end{tikzpicture}
\end{document}
4

I think that a problem could be nodes alignment. A matrix of nodes uses a base alignment by default which is different for letters and numbers and looks like letters nodes are larger thant number ones. If you change it to center, all of them are equal.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}
\matrix [matrix of nodes, nodes={draw, inner sep=0pt, anchor=center}, minimum size = 1.25em,
row sep=-\pgflinewidth, column sep=-\pgflinewidth,
column 1/.style={nodes={fill=blue!20}}]
{
A & 1 & 2 \\
B & 3 & 4 \\
C & 5 & 6 \\
};

\end{tikzpicture}

\begin{tikzpicture}
\matrix [matrix of nodes, nodes={draw, inner sep=0pt}, minimum size = 1.25em,
row sep=-\pgflinewidth, column sep=-\pgflinewidth,
column 1/.style={nodes={fill=blue!20}}]
{
A & 1 & 2 \\
B & 3 & 4 \\
C & 5 & 6 \\
};

\end{tikzpicture}
\end{document}

enter image description here

4

Diference between letters and numbers height are defined by fonts design, so this has nothing with their use for example in tikz pictures. However, if you would write your matrix in more usual way, this differences are negligible and depends on deliberate fonts design:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{matrix}

%\usepackage{libertine}

\begin{document}
    \begin{tikzpicture}
\matrix [matrix of nodes, 
         nodes={draw, minimum size=1em, inner sep=1pt, anchor=center},
         column sep=-0.5\pgflinewidth,
         row sep=-0.5\pgflinewidth
         ]
{
A & B & C \\
B & 1 & 2 \\
C & 3 & 4 \\
};

\end{tikzpicture}
\end{document}

which gives with default cm (computer modern):

enter image description here

with libertine:

enter image description here

and luximono:

enter image description here

From those examples you can see that also letters not have exactly the same heights, that difference are negligible, deliberately selected to give better optical impression at reading text.

If this bother you, find fonts, which has this differences smaller ( or design own fonts ;-) ).

You must log in to answer this question.

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