Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

enter image description here

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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}

enter image description here

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

share|improve this answer

Your Answer

 
discard

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.