答案1
不使用 TikZ 的基于 Plain TeX 的解决方案:
\newbox\wtilde
\setbox\wtilde=\hbox{%
\pdfliteral{q 2 0 0 2 0 0 cm}\lower1.5ex\rlap{$\widetilde{\hphantom{xxx}}$}\pdfliteral{Q}%
\hphantom{xxxxxx}}
$$
\pmatrix{1&1&1&1\cr1&1&1&1\cr1&1&1&1\cr1&1&1&1}
\vcenter{\baselineskip=.7\baselineskip\halign{\hfil$\scriptstyle#$\hfil\cr
r_2 - r_1 \cr
r_3 - 2r_1 \cr
\copy\wtilde \cr
r_4 - 2r_2 \cr
\null \cr
}}
\pmatrix{1&1&1&1\cr1&1&1&1\cr1&1&1&1\cr1&1&1&1}
$$
\bye
答案2
只是为了好玩:基于这个答案以及calligraphy
同一作者的图书馆。
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,calligraphy,decorations.pathreplacing}
% based on: https://tex.stackexchange.com/a/15855/194703
\newcommand{\xwidesim}[2][]{%
\setbox0\hbox{$\scriptstyle#2$}%
\setbox1\hbox{$\scriptstyle#1$}%
\mathrel{\begin{tikzpicture}[baseline=0pt]
\pgfmathsetmacro{\wmax}{max(max(\wd0,\wd1)+4,12)}
\node[above] at (0,{0.2*\wmax*1pt}) (a) {\(\scriptstyle #2\)};
\node[below] at (0,0) (b) {\(\scriptstyle #1\)};
\pen (-135:{min(\wmax,10)*0.1pt}) -- (45:{min(\wmax,10)*0.1pt});
\path (-\wmax*0.5pt-2pt,{0.025*\wmax*1pt+2pt}) coordinate(first)
(\wmax*0.5pt+2pt,{0.025*\wmax*1pt+2pt}) coordinate(last);
\calligraphy[light,line width=1.5pt]
(first) .. controls
($($(first)!0.25!(last)$)!{0.1*\wmax+0.4pt}!90:(last)$)
.. ($(first)!0.5!(last)$)
.. controls ($($(first)!0.75!(last)$)!{0.1*\wmax+0.4pt}!-90:(last)$)
.. (last);
\end{tikzpicture}}}
\begin{document}
\[
B=\begin{pmatrix}
1 & 1 & 1 & 1\\
1 & 1 & 1 & 1\\
1 & 1 & 1 & 1\\
1 & 1 & 1 & 1\\
\end{pmatrix}
\xwidesim[r_4-2r_1]{\substack{r_2-r_1\\ r_3-2r_1}}
\begin{pmatrix}
1 & 1 & 1 & 1\\
1 & 1 & 1 & 1\\
1 & 1 & 1 & 1\\
1 & 1 & 1 & 1\\
\end{pmatrix}
\xwidesim{r}
\begin{pmatrix}
1 & 1 & 1 & 1\\
1 & 1 & 1 & 1\\
1 & 1 & 1 & 1\\
1 & 1 & 1 & 1\\
\end{pmatrix}
\]
\end{document}
答案3
tikz 尝试(从我的知乎上之前的回答, 用中文(表达):
\documentclass{article}
\usepackage{tikz}
\usepackage{xparse}
\makeatletter
\def\sim@x@scale{.15}
\def\sim@y@scale{.05}
\def\sim@y@thick{.02}
\newsavebox\sim@upper
\newsavebox\sim@lower
% extensible sim symbol
\NewDocumentCommand{\xSim}{ O{} m }{%
\TextOrMath{%
\PackageError{TEST}{`\string\xSim` is valid in math mode only.}{}%
}{
% math mode only, hence no need to eliminate spaces
\sbox\sim@upper{$\scriptsize #2$}
\sbox\sim@lower{$\scriptsize #1$}
\pgfmathparse{min(max(\wd\sim@upper/1em, \wd\sim@lower/1em, 1.0), 1.5)}
\edef\sim@ratio{\pgfmathresult}
\def\sim@x {\sim@x@scale * \sim@ratio}
\def\sim@y {\sim@y@scale * \sim@ratio}
\def\sim@@y{\sim@y@thick * \sim@ratio}
\pgfmathparse{floor(max(\wd\sim@upper/1em, \wd\sim@lower/1em)) + 1}
\edef\sim@wd{\pgfmathresult em}
\mathrel{
\begin{tikzpicture}[baseline=-.7ex]
\filldraw[line width=.2pt]
(0, 0)
.. controls +(\sim@x, \sim@y+\sim@@y) and +(-\sim@x, -\sim@y) ..
+(\sim@wd, 0)
node[midway, above] {\usebox\sim@upper}
node[midway, below] {\usebox\sim@lower}
.. controls +(-\sim@x, -\sim@y-\sim@@y) and +(\sim@x, \sim@y) ..
(0, 0);
\end{tikzpicture}
}
}%
}
\makeatother
\begin{document}
\foreach \x in {a, aa, aaa, aaaa, aaaaa, aaaaaaaaaaaaaaaaaaa} {
$\frac12 A \xSim{\x} B \sim C \xSim[\x]{} D$ \par
}
\end{document}