[Tex/LaTex] How to draw a separator between the columns of a matrix.

matricestikz-pgf

Is there a simple way to tell TikZ that I want a vertical line to separate the columns of a matrix? I know how to draw them manually, I am looking for an automatic solution, maybe using styles or something.

Best Answer

You can use "matrix of nodes" and anchors:

\begin{tikzpicture}
\matrix (mat) [matrix of nodes]
 {
  1 & 2 & 3 \\
  1 & 2 & 3 \\
  1 & 2 & 3 \\
  1 & 2 & 3 \\
 };
% Matrix is called 'mat' first number is row, second numer is column
\draw[thick,red] (mat-1-1.north east) -- (mat-4-1.south east);
\end{tikzpicture}