I want to show a distance matrix as
in LaTeX, and I try:
\documentclass{article}
\usepackage{amsmath,amssymb}
\begin{document}
We obtain a distance matrix as follows:
$$
\boldsymbol{D}={d_{ij}}=
\begin{array}{c}
\begin{matrix} 1 & 2 & 3 & 4 & 5 \end{matrix}
\
\begin{matrix} 1 \ 2 \ 3 \ 4 \ 5 \end{matrix}
\begin{bmatrix}
0 & & & & \
9 & 0 & & & \
3 & 7 & 0 & & \
6 & 5 & 9 & 0 & \
11 & 10 & 2 & 8 & 0
\end{bmatrix}
\end{array}
$$
\end{document}
It shows
which displays a mediocre result, and the alignment of the result (which I am not very satisfied with) can still be improved.
If one only use basic \usepackage{amsmath,amssymb} without using other (complex) packages, like \usepackage{kbordermatrix}, how can one improve the alignment in a concise and elegant way? P.S.: Simple native LaTeX commands can be easily applied to Markdown mathematical equations.
Also, try to avoid using manual adjustments like \qquad, \quad, \:, \;, etc., for spacing in LaTeX. This is because if the numbers inside the matrix change (e.g., from 2 to 200), it will further increase the alignment workload.





OPwants to implement the code intoMarkdown, is this suggestion supportsMarkdown? please advise. Excuse if my understanding is wrong – MadyYuvi Feb 29 '24 at 09:59\[...\]is preferable to$$ ... $$in pure tex editors (eg. TeXStudio), but$$ ... $$can provide real-time rendering of mathematical equations in markdown (editors), making it intuitive and efficient. ps: Personally, I don't like LyX either. It can be bloated and inefficient. – John Stone Mar 01 '24 at 01:34