悠闲数学娱乐论坛(第2版)'s Archiver

kuing 发表于 2018-8-18 23:06

自适应长度波浪~

问题来自:[url]http://bbs.ctex.org/forum.php?mod=viewthread&tid=155125[/url]
[quote][求助中] 关于矩阵的等价符号
发表于 2018-5-12 16:36:29
[attach]6547[/attach]
如上图所示。红色框内的等价符号要怎么打出来以及排版呀,先谢谢各位了[/quote]
原帖中各种方法搞出来的感觉都不怎么好。

前几天一直在研究箭头,对可伸长箭头的构造算是有点了解,但对于这种长波浪,也无法照搬,因为正如原帖中满庭芳所说:tilde 这种非“重复性”的曲线,不能跟直线或由重复的片断组成的波浪线等那样、由多个小片断自动根据长度连缀起来,……

我本来想对已有的小波浪(如 \tilde、\textasciitilde 或者中文的 ~)作拉伸来达到效果,其中 \textasciitilde 较合适,因为它看起来位于公式的轴(即分数线位置)上,但实操后发现不行,因为这个字符的实际高度并非关于轴对称,用框把它框起来是这样的:[attach]6548[/attach],一旦在竖直方向上作拉伸,位置就不对了,用 \vcenter 也移不准,当然或许有其他手段可以移准,但懒得想了,因为我决定用 \tikz 仿制一个纯粹的波浪,纯粹指的是高度完全由线条自身来决定,这样用 \vcenter 就一定准,而且仿制的话,我还可以找一个较长的波浪来仿制,这样拉伸的效果应该会更好。

我仿制的是 mtextra.ttf 中的一条长波浪(并没考虑太多,随便在系统字体里找的),用 fontforge 打开截图到几何画板里,然后描点获取边界上的一列坐标(只需描一边,另一边对称),这样用 \fill plot[smooth] coordinates {点列} 的方式就可以画出一条看起来差不多的波浪了。

为了自适应长度,需要解决比例问题,这问题并不简单,因为如果只是纯粹横向拉伸或者整体放缩,那效果也不会好看(否则字体设计者也不用专门为一个符号设计多个大小不同的字体了),我的想法是,让 yscale = f(xscale),f 满足近处较陡远处较平,即短时表现为整体放缩,长时表现为横向拉伸,综合了两者。

在写具体代码时,前几天研究 amsmath.sty 所学到的东东倒是可以用上,故此我干脆就把上波浪(类似于向量箭头那种)也顺手做了,在代码中你会发现,居中波浪和上波浪我采用了不同的 f。

过程中其实还有很多细节问题是值得说的,但已经废话了那么多了,还是直接放代码吧。[code]\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

%===画波浪===
\newcommand\orilongtilde[2]{\vcenter{\hbox{%
\tikz[xscale=#1,yscale=#2]{
\fill plot[smooth] coordinates{
(1,0.061)(0.642,-0.052)(0.417,-0.094)(0.236,-0.094)
(0.097,-0.067)(-0.022,-0.027)(-0.144,0.012)
(-0.283,0.039)(-0.459,0.036)(-0.678,0)(-1,-0.097)
}
-- plot[smooth] coordinates{
(-1,-0.061)(-0.642,0.052)(-0.417,0.094)(-0.236,0.094)
(-0.097,0.067)(0.022,0.027)(0.144,-0.012)
(0.283,-0.039)(0.459,-0.036)(0.678,0)(1,0.097)
}
--cycle;}}}}

%===上波浪===
\newcommand\overtildeo[1]{%
\pgfmathparse{scalar(#1/2cm)}\let\bilitmp\pgfmathresult
\orilongtilde{\bilitmp}{8*\bilitmp/(20*\bilitmp+1)}}
%以下参考了amsmath.sty
\makeatletter
\newcommand\overtildeoo[2]{\setbox\tw@\hbox{$\m@th#1#2$}%
\vbox{\ialign{##\crcr$\overtildeo{\wd\tw@}$\crcr
\noalign{\nointerlineskip}\unhbox\tw@\crcr}}}
\makeatother
\newcommand\overtilde{\mathpalette\overtildeoo}

%===中波浪===
\newcommand\longtildeo[1]{%
\pgfmathparse{scalar(#1/2cm)}\let\bilitmp\pgfmathresult
\orilongtilde{\bilitmp}{0.6*\bilitmp^(1/3)}}
\newcommand\longtilde[1]{\mathrel{\longtildeo{#1}}}
%以下参考了amsmath.sty
\makeatletter
\newcommand\xlongtilde[2][]{%
  \mathrel{\mathop{%
    \setbox\tw@\vbox{\m@th
      \hbox{$\scriptstyle\mkern10mu{#1}$}%
      \hbox{$\scriptstyle\mkern10mu{#2}$}%
    }%
    {\longtildeo{\wd\tw@}}%
    \raise1.16ex\hbox{}%让\ht大点
    }%
  \limits
    \@ifnotempty{#2}{^{#2}}%
    \@ifnotempty{#1}{_{#1}}}%
}
\makeatother

\linespread{1.3}

\begin{document}

overtilde test:

$\overtilde a$ vs $\overrightarrow a$,
$\overtilde A$ vs $\overrightarrow A$,
$\overtilde{AB}=\overtilde{ABC}=\overtilde{ABCD}=\overtilde{ABCDE}$

$\overtilde{AAAAAAAAAAAA}$

\foreach \i in {0.4,0.8,...,4}
{$A=\overtilde{\rule{\i em}{1.66ex}}$\par}

xlongtilde test:

$A\xlongtilde\triangle A\xlongtilde[you]{fuck}A
\xrightarrow[you]{fuck}A$

\foreach \i in {0.4,0.8,...,4}
{$A\xlongtilde{\rule{\i em}{1ex}}B-C$\par}

\[A \xrightarrow[r_4-3r_2]{\substack{r_2\div2\\r_3+5r_2}}
A \xlongtilde[r_4-3r_2]{\substack{r_2\div2\\r_3+5r_2}}
\begin{pmatrix}
1&1&-2&1&4\\
0&1&-1&1&0\\
0&0&0&2&-6\\
0&0&0&1&-3
\end{pmatrix}\]

no x version, can set the length as you like:

$A\longtilde{2em}B$

$A\longtilde{1cm}B$

$A\longtilde{3cm}B$

\end{document}[/code]效果:
[attach]6544[/attach]
[attach]6545[/attach]
[attach]6546[/attach]

如果觉得不好看,也可以自行调整控制比例的那个函数,又或者重新画一个波浪。

kuing 发表于 2022-4-19 12:01

也看到一个tikz画的:[url]https://www.zhihu.com/answer/870883390[/url]
有空再仔细看

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.