# Horizontal alignment of text nodes of varying length in Tikz matrix like in Tex tabular

In tablular, we use {r|c|l} to define alignment. Is there anything similar for Tikz matrix. For example, by using matrix, the following MWE produces matrix of nodes, which appear to be center aligned for each column.

However, I would like to have the nodes in the first column right-aligned, the middle column center-aligned, while the third column left-aligned. How would I achieve this? (also note, the nodes may have different styles)

\documentclass[border=5pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}[align=center]
\matrix[matrix of nodes,row sep=0.5cm,column sep=2cm,
nodes={rectangle, draw}]{
col1 & col2 & col3 \\
col111111111 & col2222222222 & col33333\\
col1111 & col22222 & col3333333333 \\
};

\end{tikzpicture}
\end{document}


yields this:

-

Tikz matrices define the styles column X which allows to pass separate options (in this case, anchor) for different columns. For the record, the row X styles are the equivalent for rows, and you can combine both to refer to a specific cell.

\documentclass[border=5pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}[align=center]
\matrix[matrix of nodes,row sep=0.5cm,column sep=2cm,
nodes={rectangle, draw},
column 1/.style={anchor=base east},
column 2/.style={anchor=base},
column 3/.style={anchor=base west}
]{
col1 & col2 & col3 \\
col111111111 & col2222222222 & col33333\\
col1111 & col22222 & col3333333333 \\
};

\end{tikzpicture}
\end{document}


More information is available in the pgfmanual (section 17.3.3).

-