3

I was trying to build a matrix with vertical, horizontal and diagonal dots, but I'm pretty disappointed by the result. The spaces between each line aren't always equal, and same applies to colums. Could anyone come to help me please? Here is my code:

$$A = \begin{pmatrix}
1 & 0 &  & \dots & &  0 \\
d & e & f & & &\vdots \\
0 & d & e & f & \\
\vdots & &  \ddots & \ddots & \ddots & 0 \\
  &  &   & d & e & f \\
0 & &  \dots  & & 0 & 1 
\end{pmatrix}$$
Pablito
  • 107
  • Side note --- it's recommended that you don't use $$ in LaTeX, but instead reach for \[ ... \], or use one of the named environments, e.g. equation* from amsmath. See https://tex.stackexchange.com/q/503/158639 . – chsk Mar 31 '21 at 21:16

3 Answers3

2

I suggest nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

[\renewcommand{\arraystretch}{1.1} A = \begin{pNiceMatrix}[nullify-dots,xdots/shorten=3pt] 1 & 0 & & \Cdots & & 0 \ d & e & f & & &\Vdots \ 0 & d & e & f & \ \Vdots & & \Ddots & \Ddots & \Ddots & 0 \ & & & d & e & f \ 0 & & \Cdots & & 0 & 1 \end{pNiceMatrix}]

\end{document}

Output of the above code

F. Pantigny
  • 40,250
1

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    % Dots in all rows/columns
    \[
        A = 
        \begin{pmatrix}
            1       & 0     &   0    &   0    & \dots  &   0    \\
            d       & e     &   f    &   0    &        & \vdots \\
            0       & d     &   e    &   f    &        & \vdots \\
            \vdots  &       & \ddots & \ddots & \ddots & \vdots \\
            \vdots  &       &        &   d    &   e    &   f    \\
            0       & \dots & \dots  & \dots  &   0    &   1
        \end{pmatrix}
    \]
    % Remove most dots and excess zeros
    \[
        A = 
        \begin{pmatrix}
            1 &   &        &        &        &    \\
            d & e &   f    &        &        &    \\
              & d &   e    &   f    &        &    \\
              &   & \ddots & \ddots & \ddots &    \\
              &   &        &   d    &   e    &  f \\
              &   &        &        &        &  1
        \end{pmatrix}
    \]
    % Remove most dots but add some zeros back
    \[
        A = 
        \begin{pmatrix}
            1 & 0 &    0   &        &        &    \\
            d & e &    f   &        &    0   &    \\
              & d &    e   & f      &        &    \\
              &   & \ddots & \ddots & \ddots &    \\
              & 0 &        &   d    &   e    &  f \\
              &   &        &   0    &   0    &  1
        \end{pmatrix}
    \]
\end{document}

Here's a few ways of doing it still using the pmatrix environment. The weird spacing is caused by the vertical height/width of \vdots/\dots/\ddots. The first solution is simply to make sure that every column and row has vertical and horizontal dots so the spacing is the same. The second option is to remove dots except for the \ddots and then these only appear in one row and are the only things in the row so the spacing looks better. The third option is similar but with the fact that the rest of the matrix is zero indicated by a few zeros.

Willoughby
  • 3,649
0

I have adapted your matrix in function of this old question where the very nice user @Steven B. Segletes use tabstackengine:

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath,amssymb}
\usepackage{tabstackengine}
\stackMath

\begin{document}

[ \setstackgap{L}{1\baselineskip} \fixTABwidth{T} A = \parenMatrixstack{ 1 & 0 & & \dots & & 0 \ d & e & f & & & \vdots \ 0 & d & e & f & & 0\ \vdots & & \ddots & \ddots & \ddots & 0 \ & & & d & e & f \ 0 & & \dots & & 0 & 1 } ]

\end{document}

enter image description here

Sebastiano
  • 54,118