5

enter image description here How can I type this form of a matrix in LaTeX?

5

Use the kbordermatrix package. (I think for licence reasons it cannot be included in the TeX distributions.)

enter image description here

\documentclass{article}
\usepackage{rotating}
\usepackage{kbordermatrix}
\begin{document}
\[ C = \raisebox{-2\baselineskip}{%
   \begin{tabular}[b]{c@{\hspace*{0.5em}}c}
   & To node
   \\
     \begin{sideways}
       From node
     \end{sideways}
   & \raisebox{0.5\height}%
       {\(\kbordermatrix
            { &  1  &   2 &  3  &  4  &  5  \\
            1 &  1  & x_1 & x_5 &  0  &  0 \\
            2 & x_1 &  1  & x_2 & x_3 & x_4 \\
            3 & x_5 & x_2 &  1  & x_6 &  0  \\
            4 &  0  & x_3 & x_6 &  1  & x_7 \\
            5 &  0  & x_4 &  0  & x_7 & 1
            }
        \)%
       }
   \end{tabular}}
\]
\end{document}
  • kbordermatrix is included in MiKTeX distribution... – Arzigoglu Dec 22 '16 at 18:46
7

Something similar can be done with TikZ. The baseline correction of the matrix is achieved by means of egreg’s formula.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\[
C =
\begin{tikzpicture}[baseline={([yshift=-\dimexpr\fontdimen22\textfont2\relax]M.center)}]
  \matrix [
    matrix of math nodes,
    left delimiter={[}, right delimiter={]},
    inner sep=1pt, column sep=1ex, row sep=1ex,
    execute at begin cell=\mathstrut,
  ] (M) {
    1 & x_1 & x_5 &  0  &  0 \\
    x_1 &  1  & x_2 & x_3 & x_4 \\
    x_5 & x_2 &  1  & x_6 &  0  \\
    0  & x_3 & x_6 &  1  & x_7 \\
    0  & x_4 &  0  & x_7 & 1 \\
  };

  \foreach \c in {1,...,5}
    \node[above=1em] at (M-1-\c) {$\scriptstyle\c$};
  \foreach \r in {1,...,5}
    \node[left=1.5em] at (M-\r-1) {$\scriptstyle\r$};

  \node[above=2em] at (M-1-3) {To node};

  \node[rotate=90,above=2.5em] at (M-3-1) {From node};
\end{tikzpicture}
\]
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.