12

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:

enter image description here

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

2 Answers 2

8

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}

enter image description here

1
  • works perfect !
    – jiri jansa
    Commented Oct 23, 2012 at 7:30
3

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).

Output of the above code

You must log in to answer this question.

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