答案1
基于 TeX 基元 的解决方案\hbox
, \vbox
, \hrule
, \vrule
:\halign
\newdimen\colw \colw=3.2em
\let\col\hbox
\def\bmkern{\ifx\col\hbox \kern.25\colw \fi}
\def\bmat#1#2{{\def\col{\hbox to\colw}\bbmat{#1}{#2}}}
\def\bbmat#1#2{\vbox{\everymath={\scriptstyle}
\hrule width.5\colw
\hbox to.5\colw{\vrule \strut\hss$#1$\hss\vrule}
\hrule
\moveright\dimexpr.5\colw-.4pt\hbox{\vrule
\vtop{\kern1ex
\halign{&\col{\bmkern\hss$##$\hss\bmkern}\cr#2\crcr}
\kern1ex\hrule}%
\vrule
}
}}
\def\hmat#1{\par
\moveright 1.25\colw\vbox{\everymath={\scriptstyle}
\halign{&\hbox to\colw{\hss$##$\hss}\cr #1\crcr}}
\nobreak\vskip-\baselineskip
}
\hmat{v_1 & v_2 & v_3 & v_{\rm out} && v_{\rm in} & v_{\rm gnd}}
\bbmat{A} {
\bmat{P} {{1\over R_1} + sC_1 & 0 & 0 & 0 \cr
-1 & 1 & 0 & 0 \cr
0 & -sC_2 & {1\over R_2} + sC_2 & 0 \cr
0 & 0 & -1 & 1 }
&
\bmat{Q^T} {-{1\over R_1} & -sC_1 \cr
0 & 0 \cr
0 & -{1\over R_2} \cr
0 & 0
}
\cr \noalign{\kern1ex}
\bmat{Q} {-{1\over R_1} & 0 & 0 & 0 \cr
-sC_1 & 0 & -{1\over R_2} & 0 }
&
\bmat{R} { 1\over R_1 & 0 \cr
0 & {1\over R_2} + sC_1}
}
答案2
这是一个使用 的解决方案nicematrix
。所有规则均使用 命令\Block
(由nicematrix
及其键提供draw
)绘制。
\documentclass{article}
\usepackage{nicematrix,amstext}
\begin{document}
\NiceMatrixOptions{exterior-arraycolsep}
$\begin{NiceArray}{*{12}{c}}[cell-space-limits=2pt]
\Block[draw]{}{A} & & & v_1 & v_2 & v_3 & v_{\text{out}} & & & v_{\text{in}} & v_{\text{gnd}} & \\
& \Block[draw]{*-*}{}\\
& & \Block[draw]{}{P} & & & & & & \Block[draw]{}{Q^T} \\
& & & \Block[draw]{4-4}{}\frac{1}{R_1} + sC_1 & 0 & 0 & 0 & & & \Block[draw]{4-2}{} -\frac{1}{R_1} & -sC_1 \\
& & & -1 & 1 & 0 & 0 & & & 0 & 0 \\
& & & 0 & -sC_2 & \frac{1}{R_2}+sC_2 & 0 & & & 0 & -\frac{1}{R_2} \\
& & & 0 & 0 & -1 & 1 & & & 0 & 0 \\
\\
& & \Block[draw]{}{Q} & & & & & & \Block[draw]{}{R} \\
& & & \Block[draw]{2-4}{} -\frac{1}{R_1} & 0 & 0 & 0 & & & \Block[draw]{2-2}{} \frac{1}{R_1} & 0 \\
& & & -sC_1 & 0 & -\frac{1}{R_2} & 0 & & & 0 & \frac{1}{R_2}+sC_1 \\
\\
\end{NiceArray}$
\end{document}