44

I can represent an upper trapezoidal matrix say as shown below. I would like to replace all those zeros with a single big zero that spans across the low triangle rows and columns, and maybe also add a delimiter along the diagonal that clearly shows it is an upper diagonal matrix. How can I do that?

\newcommand\x{\XSolid}
%\newcommand\x{\ding{53}}
\begin{equation}
  \left(
    \begin{array}{*5{c}}
    \x & \x & \x & \x & \x \\
     0 & \x & \x & \x & \x \\
     0 &  0 & \x & \x & \x \\
     0 &  0 &  0 & \x & \x \\
     0 &  0 &  0 &  0 & \x \\
  \end{array}\right)
\end{equation}

Separate question ... why the \x command I define outputs # rather than the intended cross symbol? It outputs the same symbol # no matter if I use \XSolid or \ding{53}

UPDATE: taking the answer as input, I ended doing this:

\newcommand\x{\times}
\newcommand\bigzero{\makebox(0,0){\text{\huge0}}}
\newcommand*{\bord}{\multicolumn{1}{c|}{}}
\begin{equation}
  \left(
    \begin{array}{ccccc}
    \x    & \x       & \x    & \x    & \x \\ \cline{1-1}
    \bord & \x       & \x    & \x    & \x \\ \cline{2-2}
          & \bord    & \x    & \x    & \x \\ \cline{3-3}
          & \bigzero & \bord & \x    & \x \\ \cline{4-4}
          &          &       & \bord & \x \\ \cline{5-5}
  \end{array}\right)
\end{equation}

which produces this:

enter image description here

3
  • 1
    \documentclass{article}\begin{document}\XSolid\end{document} results in ! Undefined control sequence., thus I assume you are loading a package to define \XSolid? Which package/which version, please?
    – Stephen
    Aug 30, 2012 at 15:17
  • good question! I have no idea :D it is a large report and I have been adding packages as needed. As I understand \XSolid has been defined somewhere but I have no idea where exactly. Oh I think the package that defines \XSolid is TikZ
    – SkyWalker
    Aug 30, 2012 at 15:22
  • 1
    You could place a \show\XSolid in the preamble. When it is still undefined, it will print to the log "> \XSolid=undefined. ", when it is defined it will give the definition, and if the definition is changed (from X to #), it will give a changed definition. For a lot of packages this might be a lot of work to find which package (re-)defines it...
    – Stephen
    Aug 30, 2012 at 15:29

3 Answers 3

34
\documentclass[]{article}
\usepackage{mathtools}
\begin{document}

\[
    \left(
    \begin{array}{ccccc}
    1                                    \\
      & 1             &   & \text{\huge0}\\
      &               & 1                \\
      & \text{\huge0} &   & 1            \\
      &               &   &   & 1
    \end{array}
    \right)
\]  

\end{document}

enter image description here

or \makebox(0,0){\text{\huge0}} if you want to have the same line spacing.

2
  • perfect! good catch about the line spacing .. I was getting nervous about it :D then saw your timely edit :) perfect!
    – SkyWalker
    Aug 30, 2012 at 15:24
  • Instead of \makebox(0,0){...} You can use \smash{\text{\huge 0}}. It also easier to insert in LyX which doesn't seem to support the \makebox(...) (width,height) option.
    – Guy
    Nov 8, 2014 at 20:13
11

Just in case : you might need repeated dots across the diagonal. Here is a ugly way to do so.

\newcount\dotcnt\newdimen\deltay
\def\Ddot#1#2(#3,#4,#5,#6){\deltay=#6\setbox1=\hbox to0pt{\smash{\dotcnt=1
\kern#3\loop\raise\dotcnt\deltay\hbox to0pt{\hss#2}\kern#5\ifnum\dotcnt<#1
\advance\dotcnt 1\repeat}\hss}\setbox2=\vtop{\box1}\ht2=#4\box2}

And an exemple (using amsmath, of course) :

\[\begin{pmatrix}
1\Ddot{12}.(6pt,-2pt,6pt,-5pt)&1\Ddot8.(9pt,2pt,6pt,0pt)&\quad&\quad&1\\
&&&&\\
&&&&\\
&&&&\\
&\mbox{\Huge 0}&&&\\
&&&&1\\
\end{pmatrix}\]

\Ddot in action

5
  • 1
    why don't you use \ddots and \cdots instead?
    – user2478
    Aug 30, 2012 at 21:36
  • 2
    It is really painful to adjust various \ddots across lines & columns of the matrix and, anyway, these \ddots never join up properly.
    – rcabane
    Sep 1, 2012 at 8:04
  • One more note : the width of the various elements has some influence onto the column widths and line heights. The suggested macro gives a zero width & height to the repeated dots, while \cdots and \ddots give a non-zero width.
    – rcabane
    Sep 9, 2012 at 12:44
  • Is there also a non-ugly way to do this?
    – Christian
    Nov 28, 2013 at 20:39
  • I don't know ! Do you have any ideas ?
    – rcabane
    Dec 24, 2013 at 13:01
1

With {pNiceMatrix} of nicematrix.

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

\begin{document}

$\begin{pNiceMatrix}[left-margin]
\times & \times & \times & \times & \times \\
       & \times & \times & \times & \times \\
       &        & \times & \times & \times \\ 
\Block{2-2}<\Huge>{0}
       &        &        & \times & \times \\
       &        &        &        & \times \\
\CodeAfter
 \tikz \draw (2-|1) -| (3-|2) -| (4-|3) -| (5-|4) -| (6-|5) ;
\end{pNiceMatrix}$

\end{document}

Output of the above code

You must log in to answer this question.

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