# diagonal line within matrix

I've got simple task - draw block of matrices, when one of the matrices contains diagonal and vertical lines. I am able to make diagonal dotted lines but so far i have not succeeded with solid line. Example of my matrix follows:

 \begin{pmatrix}
\hat{B} &         & & & \\
& ddots & & & \\
&         & ddots & & \\
&         & &  ddots \\\hline
\\
\\
& & \text{{\huge{0}}}  & &  \\
\\
\end{pmatrix}

• Commented Oct 22, 2012 at 15:38
• You mean that you want a solid line instead of the diagonal dots? Commented Oct 22, 2012 at 15:43
• I would like to have one solid diagonal line across the whole matrix, or better to say across the upper part Commented Oct 22, 2012 at 15:59
• Highly related: Diagonal dots spanning multiple lines/columns of a matrix. You can use some of those answers as well and just change the line style.
– Werner
Commented Oct 22, 2012 at 19:03

One possibility is to use \tikzmark to place marks at the beginning and end of the lines and then draw them:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\newcommand\tikzmark[1]{%
\tikz[overlay,remember picture,baseline] \node [anchor=base] (#1) {};}

\newcommand\MyLine[3][]{%
\begin{tikzpicture}[overlay,remember picture]
\draw[#1] (#2.north west) -- (#3.south east);
\end{tikzpicture}}

\begin{document}

$\begin{pmatrix} \phantom{0}\tikzmark{a} & & & & \\ & & & & \\ & & & & \\ & & & & \tikzmark{b}\phantom{0}\\\hline \\ \\ \multicolumn{5}{c}{\text{\huge 0}} \\ \\ \end{pmatrix}\qquad \begin{pmatrix} \phantom{0}\tikzmark{c} & \phantom{0}\tikzmark{e} & & & \\ & & & & \\ & & & & \tikzmark{f}\phantom{0} \\ & & & & \tikzmark{d}\phantom{0}\\\hline \\ \\ \multicolumn{5}{c}{\text{\huge 0}} \\ \\ \end{pmatrix}$
\MyLine[ultra thick]{a}{b}
\MyLine[blue,thick]{c}{d}
\MyLine[blue,thick]{e}{f}

\end{document}


• works perfect ! Commented Oct 23, 2012 at 7:30

With {pNiceMatrix} of nicematrix, it's straightforward.

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

$\begin{pNiceMatrix}[xdots={line-style=solid,shorten=6pt},nullify-dots,columns-width=3mm] \Ddots & \Ddots & \Ddots & \Ddots & \\ & & & & \\ & & & & \\ & & & & \\ \hline \Block{4-5}<\Huge>{0} & & & & \\ & & & & \\ & & & & \\ & & & & \\ \end{pNiceMatrix}$

\end{document}


You need several compilations (because nicematrix PGF/Tikz nodes under the hood).