# Creating table using TikZ matrix

I'm trying to create a table in TikZ with

1. the first column right-aligned, and the texts in each cell on the same line
2. the rest of the columns center-aligned, and each has width of 1cm

My attempt is as follows:

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

\begin{document}

\begin{tikzpicture}
\matrix(dict)[matrix of nodes,below=of game,
nodes={align=center,text width=1cm},
row 1/.style={anchor=south},
column 1/.style={text width=2cm,align=right},
]{
meaning & $b_1$ & $b_2$ & $b_3$ & $b_1b_2$ & $b_1b_3$ & $b_2b_3$ & $b_1b_2b_3$\\
common list \\
private list\\
};
\draw(dict-1-1.south west)--(dict-1-8.south east);
\draw(dict-1-1.north east)--(dict-3-1.south east);
\end{tikzpicture}

\end{document}


The output is not as desired, since the texts in cells dict-2-1 and dict-3-1 spread over two lines. Also, texts in column 1 is not right aligned, despite column 1/.style being specified after node/.style.

What should I do?

• The order of the options in the \matrix doesn’t matter because here you only append to style every node and define style column 1. The order of usage matters (in the internals of the \matrix macro). Either way, you need to do column 1/.style={nodes={text width=2cm,align=right}}. What is the purpose of row 1? – Qrrbrbirlbel Jul 31 '13 at 1:25
• @Qrrbrbirlbel: Thanks! Your suggestion works. How about making it into an actual answer? row 1 aligns the nodes by their bottom border, so that the horizontal line doesn't have a slope. – Herr K. Jul 31 '13 at 3:32

# Remarks

This is just @Qrrbrbirlbel's comment converted to an answer.

# Implementation

\documentclass[tikz]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix(dict)[matrix of nodes,%below=of game,
nodes={align=center,text width=1cm},
row 1/.style={anchor=south},
column 1/.style={nodes={text width=2cm,align=right}}
]{
meaning & $b_1$ & $b_2$ & $b_3$ & $b_1b_2$ & $b_1b_3$ & $b_2b_3$ & $b_1b_2b_3$\\
common list \\
private list\\
};
\draw(dict-1-1.south west)--(dict-1-8.south east);
\draw(dict-1-1.north east)--(dict-3-1.south east);
\end{tikzpicture}
\end{document}