![我如何在 LaTeX 中输入这种形式的矩阵?](https://linux22.com/image/346345/%E6%88%91%E5%A6%82%E4%BD%95%E5%9C%A8%20LaTeX%20%E4%B8%AD%E8%BE%93%E5%85%A5%E8%BF%99%E7%A7%8D%E5%BD%A2%E5%BC%8F%E7%9A%84%E7%9F%A9%E9%98%B5%EF%BC%9F.png)
答案1
使用kbordermatrix 包. (我认为由于许可原因它不能包含在 TeX 发行版中。)
\documentclass{article}
\usepackage{rotating}
\usepackage{kbordermatrix}
\begin{document}
\[ C = \raisebox{-2\baselineskip}{%
\begin{tabular}[b]{c@{\hspace*{0.5em}}c}
& To node
\\
\begin{sideways}
From node
\end{sideways}
& \raisebox{0.5\height}%
{\(\kbordermatrix
{ & 1 & 2 & 3 & 4 & 5 \\
1 & 1 & x_1 & x_5 & 0 & 0 \\
2 & x_1 & 1 & x_2 & x_3 & x_4 \\
3 & x_5 & x_2 & 1 & x_6 & 0 \\
4 & 0 & x_3 & x_6 & 1 & x_7 \\
5 & 0 & x_4 & 0 & x_7 & 1
}
\)%
}
\end{tabular}}
\]
\end{document}
答案2
TikZ 也可以做类似的事情。矩阵的基线校正是通过以下方式实现的埃格雷格公式。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\[
C =
\begin{tikzpicture}[baseline={([yshift=-\dimexpr\fontdimen22\textfont2\relax]M.center)}]
\matrix [
matrix of math nodes,
left delimiter={[}, right delimiter={]},
inner sep=1pt, column sep=1ex, row sep=1ex,
execute at begin cell=\mathstrut,
] (M) {
1 & x_1 & x_5 & 0 & 0 \\
x_1 & 1 & x_2 & x_3 & x_4 \\
x_5 & x_2 & 1 & x_6 & 0 \\
0 & x_3 & x_6 & 1 & x_7 \\
0 & x_4 & 0 & x_7 & 1 \\
};
\foreach \c in {1,...,5}
\node[above=1em] at (M-1-\c) {$\scriptstyle\c$};
\foreach \r in {1,...,5}
\node[left=1.5em] at (M-\r-1) {$\scriptstyle\r$};
\node[above=2em] at (M-1-3) {To node};
\node[rotate=90,above=2.5em] at (M-3-1) {From node};
\end{tikzpicture}
\]
\end{document}