[Tex/LaTex] A matrix with vertical, horizontal and diagonal lines

matrices

How could I draw with LaTeX such a matrix?

enter image description here

I've looked around but didn't find any solution.

Best Answer

Doing the matrix with amsmath's pmatrix and the lines with tikz and tikzmark:

enter image description here

\documentclass{article}

\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc}
\newdimen\numht
\newdimen\numwd

\begin{document}
\pagenumbering{gobble}
\settowidth{\numwd}{0}
\settoheight{\numht}{(}

\begin{equation*}
  \begin{pmatrix}
    1\tikzmark{a} & & & \tikzmark{b}1\\
    0\tikzmark{c} & \\
    \\
    0\tikzmark{d} & & \tikzmark{e}0 & \tikzmark{f}1\\
  \end{pmatrix}
\end{equation*}

\begin{tikzpicture}[remember picture, overlay]
  \draw ($(pic cs:a)+(0,0.5\numht)$) -- ($(pic cs:b)+(0,0.5\numht)$);
  \draw ($(pic cs:a)+(0,0.0\numht)$) -- ($(pic cs:f)+(0,1 \numht)$);
  \draw ($(pic cs:c)+(0,0.0\numht)$) -- ($(pic cs:e)+(0,1 \numht)$);
  \draw ($(pic cs:c)+(-0.5\numwd,-1pt)$) -- ($(pic cs:d)+(-0.5\numwd,\numht)$);
  \draw ($(pic cs:d)+(0,0.5\numht)$) -- ($(pic cs:e)+(0,0.5\numht)$);
  \draw ($(pic cs:b)+(0.5\numwd,-1pt)$) -- ($(pic cs:f)+(0.5\numwd,\numht)$);
\end{tikzpicture}

\end{document}

Or, greatly simplified by Mr. marmot:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\newcommand{\tikznode}[2]{%
\ifmmode%
\tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {$#2$};%
\else
\tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {#2};%
\fi}
\begin{document}

\begin{equation*}
  \begin{pmatrix}
    \tikznode{a}{1} & & & \tikznode{b}{1}\\
    \tikznode{c}{0} & \\
    \\
    \tikznode{d}{1} & & \tikznode{e}{0} & \tikznode{f}{1}\\
  \end{pmatrix}
\end{equation*}

\begin{tikzpicture}[remember picture, overlay,shorten >=1pt,shorten <=1pt]
  \draw (a) -- (b);
  \draw (c) -- (e);
  \draw (c) -- (d);
  \draw (d) -- (e);
  \draw (a) -- (f);
  \draw (b) -- (f);
\end{tikzpicture}

\end{document}