1
\begin{center}\begin{tikzpicture}
  \matrix (m)
    [
      matrix of math nodes,
      row sep    = 3em,
      column sep = 4em
    ]
    {
      1 & 3 \\
      2 & 4\\
    };
\end{tikzpicture}\end{center}

I'd like to draw a vertical line to separate the two sides of the matrix. I realize one can extend the matrix and such but I'd rather have something that is a bit more general and doesn't explicitly depend on a bunch of stuff(such as specifying nodes, extending the matrix size, computing mid points using some package, etc). (this way it works for more complex examples).

Bernard
  • 271,350

1 Answers1

2

try

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

\begin{document}
\begin{tikzpicture}
  \matrix (m)
    [
      matrix of math nodes,
      row sep    = 3em,
      column sep = 4em
    ]
    {
      X & A \\
      Y & B\\
    };
  \draw ($(m-1-1.north east)!0.5!(m-1-2.north west)$) -- ($(m-2-1.south east)!0.5!(m-2-2.south west)$);
\end{tikzpicture}
\end{document}

enter image description here

Zarko
  • 296,517
  • This trick has already been used here and perhaps before. When I wrote that answer, I couldn't find an earlier post, but that does not mean much. –  Sep 10 '18 at 12:56
  • @marmot, i know that i didn't discover a wheel, it exist very long time :-). i accidentally had a little free time, so I wrote this simple answer. – Zarko Sep 10 '18 at 13:06