42

How can I draw a matrix with dots in tex like the one shown below:

matrix

B Faley
  • 485
  • 1
  • 4
  • 12

2 Answers2

61

I suggest you load the amsmath package, employ its the bmatrix ("bracketed matrix") environment, and use \dots (or \ldots), \vdots ("vertical dots"), and \ddots ("diagonal dots") as needed.

The following screenshot shows two ways this approach could be employed. The first replicates the matrix shown in the OP's posting. The second shows that this method can be used for square as well as non-square matrices.

enter image description here

\documentclass{article}
\usepackage{amsmath} % for 'bmatrix' environment
\begin{document}
\[
A = \begin{bmatrix} 
    a_{11} & a_{12} & \dots \\
    \vdots & \ddots & \\
    a_{K1} &        & a_{KK} 
    \end{bmatrix}
\qquad
B = \begin{bmatrix} 
    b_{11} & \dots  & b_{1M}\\
    \vdots & \ddots & \vdots\\
    b_{K1} & \dots  & b_{KM} 
    \end{bmatrix}
\]
\end{document}
Mico
  • 506,678
  • 2
    What's the usage of [ and ] before and after the matrix definition? – B Faley Sep 03 '16 at 12:04
  • 5
    @Meysam -- \[ is LaTeX code to initiate an unnumbered display-math environment, and \] is LaTeX code to terminate this environment. Please check out the posting What are the differences between $$, \[, align, equation and displaymath? for more information on the subject of TeX and LaTeX display-math environments. – Mico Sep 03 '16 at 12:07
  • \cdots might be more appropriate than \dots, depending what look exactly you're going for. – The Zach Man Oct 12 '22 at 17:04
  • @TheZachMan - As a typographic ellipsis, \cdots is generally used only as the connector between (explicit or implicit) binary operators. E.g., a_1+a_2+\cdots+c_n, or b_1 b_2 \cdots b_T. Plus, there's the multIple integration case: \int\int\cdots\int. I don't think that that's the impression one wants to create for "gaps" in a row of a matrix. Hence, I'm comfortable with using \dots (or \ldots) for the matrices at hand. – Mico Oct 12 '22 at 17:15
  • I think it's appropriate since it matches the centering of \vdots and \ddots, but fair enough. – The Zach Man Oct 12 '22 at 17:16
  • @TheZachMan - By your argument, there could never be a use case for \ldots in a matrix. That can't be quite right, can it? – Mico Oct 12 '22 at 17:20
2

For information, here is what you can do with {bNiceMatrix} with nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document} [\NiceMatrixOptions{xdots/shorten=0.5em} A = \begin{bNiceMatrix} a_{11} & a_{12} & \Ldots \ \Vdots & \Ddots & \ a_{K1} & & a_{KK} \end{bNiceMatrix} \qquad B = \begin{bNiceMatrix} b_{11} & \Ldots & b_{1M}\ \Vdots & \Ddots & \Vdots\ b_{K1} & \Ldots & b_{KM} \end{bNiceMatrix}] \end{document}

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

Output of the above code

F. Pantigny
  • 40,250