0

How can I align an adjacency matrix of a graph drawn with TikZ next to the graph? Here the adjacency matrix is an edge-origin-destination adjancency matrix, so that it indicates which edges belong to a path connecting a given origin-destination-node pair. Currently what I am doing is something like this:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta}
\begin{document}

\title{Poorly aligned matrix}

\maketitle

\section{Introduction}

\begin{equation}
    \begin{aligned}
     \begin{pmatrix}
     1&1&0&0&0&1\\
     0&1&1&1&0&0\\
     0&0&0&1&1&1
     \end{pmatrix}
    \end{aligned}
\end{equation}
\begin{tikzpicture}[auto,vertex/.style={draw,circle}]
    \node[vertex] (1) {$v_1$};
    \node[vertex,above right=1cm of 1] (2) {$v_2$};
    \node[vertex,below right=1cm of 2] (3) {$v_3$};
    
    \path[-{Stealth[]}]
      (1) edge node {1} (2) 
      (2) edge node {2} (3)
      (3) edge node {3} (1);
\end{tikzpicture}

\end{document}

But this results in the graph being placed lower left with respect to the adjacency matrix. Also how could I indicate what the columns and the rows of the matrix mean by placing the corresponding node pairs directly above (and aligned) of the columns of the matrix, and the edges to the left of the rows?

2
  • 1
    Could you please post a complete (compilable) code?
    – Bernard
    Jan 29, 2021 at 11:50
  • @Bernard Fixed. Jan 29, 2021 at 12:26

1 Answer 1

2

A solution with a simple \raisebox:

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta}

    \begin{document}

\begin{equation}
    \begin{alignedat}{2}
     & \begin{pmatrix}
     1&1&0&0&0&1\\
     0&1&1&1&0&0\\
     0&0&0&1&1&1
     \end{pmatrix}
  & \hspace{4em}& \raisebox{-0.5\height}{\begin{tikzpicture}[auto,vertex/.style={draw,circle}]
    \node[vertex] (1) {$v_1$};
    \node[vertex,above right=1cm of 1] (2) {$v_2$};
    \node[vertex,below right=1cm of 2] (3) {$v_3$};
%
    \path[-{Stealth[]}]
      (1) edge node {1} (2)
      (2) edge node {2} (3)
      (3) edge node {3} (1);
\end{tikzpicture}}
    \end{alignedat}
\end{equation}

\end{document} 

enter image description here

2
  • Great! Do you know how I could add the node pairs above the columns of the matrix? So that from left to right (v_1, v_2), (v_1, v_3), (v_2, v_3), (v_2, v_1), (v_3, v_1), (v_3, v_2) would be inserted above the columns? How about for the rows? Jan 29, 2021 at 12:51
  • 1
    If I understand well, probably using a gather environment and the graph in the 1st line, the matrix in the 2nd line. B.t. w. (unrelated to your problem), you don't have to load inputenc, unless you have an old distribution: utf8 has been supposed to be the default for nearly 3 years
    – Bernard
    Jan 29, 2021 at 12:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .