11

I'm trying visualize a very large matrix. To do so, I'm trying to use \vdots and \ddots in a bsmallmatrix enviroment. It works but they do not scale properly as \cdots do. Now, in the minimal reproducible example below, I have found a fix here which works, but only the vertical dots and not the diagonal dots. I do not understand why it does not work for \ddots.

\documentclass{article}

\usepackage{mathtools}
\newcommand{\svdots}{\raisebox{3pt}{\scalebox{.75}{\vdots}}} % <- Works
\newcommand{\sddots}{\raisebox{3pt}{\scalebox{.75}{\ddots}}} % <- Do not work

\begin{document}

\begin{equation*}
  \begin{bsmallmatrix}
    a_{11}  & a_{12}  & \cdots  & a_{1m}  \\
    a_{21}  & a_{22}  & \cdots  & a_{2m}  \\
    \svdots & \svdots & \sddots & \svdots \\
    a_{n1}  & a_{n2}  & \cdots  & a_{nm}
  \end{bsmallmatrix}
\end{equation*}

\end{document}

The compilation errors revolves around missing $ and brackets. The document complies fine when substituting \sddots for \ddots but, obviously, the ddots have the wrong size.

How do I best accomplish my desired result?

4
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. May 24, 2015 at 11:48
  • the version in the answer you reverence has $ to put the dots in math mode but you have omitted them here. May 24, 2015 at 12:09
  • @DavidCarlisle Indeed I have, adding them around the \scalebox makes no difference. \svdots still works fine, but \sddots does not. May 24, 2015 at 12:29
  • You have to say \scalebox{.75}{$\ddots$}; it's not really needed for \vdots, but it's better to add $ also around it, for consistency.
    – egreg
    May 24, 2015 at 12:45

3 Answers 3

11

The following example redefines \vdots and \ddots to get a resizable version according to the current math style. The vertical space between the dots is taken from the horizontal dots. Also the dots in \ddots match the vertical spacing of \vdots and the horizontal spacing of the horizontal dots in \cdots. \cdots adds a thin space at the right side. For a better alignment in matrices, the redefined \ddots also adds this space.

The space above \vdots and \ddots is not fixed, the space between the dots is used for the additional vertical space above the symbol. It's a tiny bit smaller in \textstyle and \displaystyle than the original symbols, but the resizing in \scriptstyle and \scriptscriptstyle is much better as the bsmallmatrix example shows.

The following example shows the bsmallmatrix with the resizable dots. Then a normal bmatrix follows to show the symbols in the normal larger style. Then the bmatrix follows with the original \vdots and \ddots, saved in \orgvdots and \orgddots.

At the end of the example, the bounding boxes for the symbols in the different math styles are shown, first the original symbols, then the redefined symbols.

\documentclass{article}

\usepackage{mathtools}

\usepackage{letltxmacro}
\LetLtxMacro\orgvdots\vdots
\LetLtxMacro\orgddots\ddots

\makeatletter
\DeclareRobustCommand\vdots{%
  \mathpalette\@vdots{}%
}
\newcommand*{\@vdots}[2]{%
  % #1: math style
  % #2: unused
  \sbox0{$#1\cdotp\cdotp\cdotp\m@th$}%
  \sbox2{$#1.\m@th$}%
  \vbox{%
    \dimen@=\wd0 %
    \advance\dimen@ -3\ht2 %
    \kern.5\dimen@
    % remove side bearings
    \dimen@=\wd2 %
    \advance\dimen@ -\ht2 %
    \dimen2=\wd0 %
    \advance\dimen2 -\dimen@
    \vbox to \dimen2{%
      \offinterlineskip
      \copy2 \vfill\copy2 \vfill\copy2 %
    }%
  }%
}
\DeclareRobustCommand\ddots{%
  \mathinner{%
    \mathpalette\@ddots{}%
    \mkern\thinmuskip
  }%
}
\newcommand*{\@ddots}[2]{%
  % #1: math style
  % #2: unused
  \sbox0{$#1\cdotp\cdotp\cdotp\m@th$}%
  \sbox2{$#1.\m@th$}%
  \vbox{%
    \dimen@=\wd0 %
    \advance\dimen@ -3\ht2 %
    \kern.5\dimen@
    % remove side bearings
    \dimen@=\wd2 %
    \advance\dimen@ -\ht2 %
    \dimen2=\wd0 %
    \advance\dimen2 -\dimen@
    \vbox to \dimen2{%
      \offinterlineskip
      \hbox{$#1\mathpunct{.}\m@th$}%
      \vfill
      \hbox{$#1\mathpunct{\kern\wd2}\mathpunct{.}\m@th$}%
      \vfill
      \hbox{$#1\mathpunct{\kern\wd2}\mathpunct{\kern\wd2}\mathpunct{.}\m@th$}%
    }%
  }%
}
\makeatother

\begin{document}

\begin{gather*}
  \begin{bsmallmatrix}
    a_{11}  & a_{12}  & \cdots  & a_{1m}  \\
    a_{21}  & a_{22}  & \cdots  & a_{2m}  \\
    \vdots & \vdots & \ddots & \vdots \\
    a_{n1}  & a_{n2}  & \cdots  & a_{nm}
  \end{bsmallmatrix}
\\
  \begin{bmatrix}
    a_{11}  & a_{12}  & \cdots  & a_{1m}  \\
    a_{21}  & a_{22}  & \cdots  & a_{2m}  \\
    \vdots & \vdots & \ddots & \vdots \\
    a_{n1}  & a_{n2}  & \cdots  & a_{nm}
  \end{bmatrix}
\\
  \begin{bmatrix}
    a_{11}  & a_{12}  & \cdots  & a_{1m}  \\
    a_{21}  & a_{22}  & \cdots  & a_{2m}  \\
    \orgvdots & \orgvdots & \orgddots & \orgvdots \\
    a_{n1}  & a_{n2}  & \cdots  & a_{nm}
  \end{bmatrix}
\end{gather*}

\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{.1pt}

\newcommand*{\test}[1]{%
  \fbox{$#1\orgvdots$}%
  \fbox{$#1\orgddots$}%
  \fbox{$#1\vdots$}%
  \fbox{$#1\ddots$}%
  \fbox{$#1\dots$}%
  \fbox{$#1\cdots$}%
  \fbox{$#1\cdotp\cdotp\cdotp$}%
}
\begin{gather*}
  \test{}\\
  \test{\scriptstyle}\\
  \test{\scriptscriptstyle}
\end{gather*}
\end{document}

Result

4
  • There’s one thing I don’t understand in your code: since there are three dots in \box0, shouldn’t it be \advance\dimen@ -3\ht2 instead of \advance\dimen@ -2\ht2 ? As I understand it, your intention is to leave in \dimen@ the dimension of the total space between the dots — there are two spaces, so you subsequently \kern by half this amount.
    – GuM
    May 24, 2015 at 14:09
  • @GustavoMezzetti You are right, it should be 3, answer updated. May 24, 2015 at 14:33
  • Just another little thing, if I’m not abusing your patience: \cdotp is a \mathpunct, so we know from the table on page 170 what the space between the dots is going to be; therefore, instead of the slightly obscure computation, couldn’t one say something like \sbox4{$#1\nonscript\,\m@th$} followed by \kern\wd4? Please don’t even think that I dare tut-tut Heiko Oberdiek from the bottom of my 560 reputation: indeed, I’ve been long in doubt whether to post this rather punctilious comment, although, as you can see, in the end I couldn’t resist… :-)
    – GuM
    May 24, 2015 at 22:42
  • @GustavoMezzetti There are many ways of doing the calculations. I had put \cdotp inside box 0 (a) to avoid the calculation of the width manually and (b) to catch the cases script and non-script styles. The space between punctuation atoms is only set in non-script styles. May 25, 2015 at 4:31
4

You are missing one additional$...$ pair:

\documentclass{article}

\usepackage{mathtools}
\newcommand{\svdots}{\raisebox{3pt}{$\scalebox{.75}{\vdots}$}} % <- Works
\newcommand{\sddots}{\raisebox{3pt}{$\scalebox{.75}{$\ddots$}$}} % <- Do not work

\begin{document}

\begin{equation*}
  \begin{bsmallmatrix}
    a_{11}  & a_{12}  & \cdots  & a_{1m}  \\
    a_{21}  & a_{22}  & \cdots  & a_{2m}  \\
    \svdots & \svdots & \sddots & \svdots \\
    a_{n1}  & a_{n2}  & \cdots  & a_{nm}
  \end{bsmallmatrix}
\end{equation*}

\end{document}

Output:

Output of sample code

3
  • … as @egreg has pointed out while I was typing my anser. :-) Consider also mimicking the definitions of \vdots and \ddots, but with reduced values for the \raises and the \kerns (I am going to leave this to egreg as well ;-) .
    – GuM
    May 24, 2015 at 12:51
  • OK, thanks! Can I ask why the additional $...$ is strictly needed around \ddots but not \vdots? That seems strangely inconsistent to me. May 24, 2015 at 13:52
  • 1
    That’s because \ddots expands to a \mathinner atom, which requires math mode, but \vdots expands directly to a \vbox, which is allowed in horizontal mode too. But as egreg says, for consistency it’s better to add $...$ around \vdots as well.
    – GuM
    May 24, 2015 at 14:17
0

For information, the package nicematrix provides homogeneous tools to construct mathematical matrices with dotted lines, included ``small matrices'' with the key small.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}
\begin{equation*}
  \begin{bNiceMatrix}[small,xdots/shorten=5pt]
    a_{11}  & a_{12}  & \Ldots  & a_{1m}  \\
    a_{21}  & a_{22}  & \Ldots  & a_{2m}  \\
    \Vdots  & \Vdots  & \Ddots  & \Vdots \\
    a_{n1}  & a_{n2}  & \Ldots  & a_{nm}
  \end{bNiceMatrix}
\end{equation*}
\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 .