免費論壇 繁體 | 簡體
Sclub交友聊天~加入聊天室當版主
分享
返回列表 发帖

自适应长度波浪~

问题来自:http://bbs.ctex.org/forum.php?mod=viewthread&tid=155125
[求助中] 关于矩阵的等价符号
发表于 2018-5-12 16:36:29
QQ截图20180818230758.jpg
2018-8-18 23:08

如上图所示。红色框内的等价符号要怎么打出来以及排版呀,先谢谢各位了

原帖中各种方法搞出来的感觉都不怎么好。

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

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

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

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

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

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

  4. %===画波浪===
  5. \newcommand\orilongtilde[2]{\vcenter{\hbox{%
  6. \tikz[xscale=#1,yscale=#2]{
  7. \fill plot[smooth] coordinates{
  8. (1,0.061)(0.642,-0.052)(0.417,-0.094)(0.236,-0.094)
  9. (0.097,-0.067)(-0.022,-0.027)(-0.144,0.012)
  10. (-0.283,0.039)(-0.459,0.036)(-0.678,0)(-1,-0.097)
  11. }
  12. -- plot[smooth] coordinates{
  13. (-1,-0.061)(-0.642,0.052)(-0.417,0.094)(-0.236,0.094)
  14. (-0.097,0.067)(0.022,0.027)(0.144,-0.012)
  15. (0.283,-0.039)(0.459,-0.036)(0.678,0)(1,0.097)
  16. }
  17. --cycle;}}}}

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

  29. %===中波浪===
  30. \newcommand\longtildeo[1]{%
  31. \pgfmathparse{scalar(#1/2cm)}\let\bilitmp\pgfmathresult
  32. \orilongtilde{\bilitmp}{0.6*\bilitmp^(1/3)}}
  33. \newcommand\longtilde[1]{\mathrel{\longtildeo{#1}}}
  34. %以下参考了amsmath.sty
  35. \makeatletter
  36. \newcommand\xlongtilde[2][]{%
  37.   \mathrel{\mathop{%
  38.     \setbox\tw@\vbox{\m@th
  39.       \hbox{$\scriptstyle\mkern10mu{#1}$}%
  40.       \hbox{$\scriptstyle\mkern10mu{#2}$}%
  41.     }%
  42.     {\longtildeo{\wd\tw@}}%
  43.     \raise1.16ex\hbox{}%让\ht大点
  44.     }%
  45.   \limits
  46.     \@ifnotempty{#2}{^{#2}}%
  47.     \@ifnotempty{#1}{_{#1}}}%
  48. }
  49. \makeatother

  50. \linespread{1.3}

  51. \begin{document}

  52. overtilde test:

  53. $\overtilde a$ vs $\overrightarrow a$,
  54. $\overtilde A$ vs $\overrightarrow A$,
  55. $\overtilde{AB}=\overtilde{ABC}=\overtilde{ABCD}=\overtilde{ABCDE}$

  56. $\overtilde{AAAAAAAAAAAA}$

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

  59. xlongtilde test:

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

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

  64. \[A \xrightarrow[r_4-3r_2]{\substack{r_2\div2\\r_3+5r_2}}
  65. A \xlongtilde[r_4-3r_2]{\substack{r_2\div2\\r_3+5r_2}}
  66. \begin{pmatrix}
  67. 1&1&-2&1&4\\
  68. 0&1&-1&1&0\\
  69. 0&0&0&2&-6\\
  70. 0&0&0&1&-3
  71. \end{pmatrix}\]

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

  73. $A\longtilde{2em}B$

  74. $A\longtilde{1cm}B$

  75. $A\longtilde{3cm}B$

  76. \end{document}
复制代码
效果:
QQ截图20180818224224.png
2018-8-18 23:06

QQ截图20180818224258.png
2018-8-18 23:06

QQ截图20180818224316.png
2018-8-18 23:06


如果觉得不好看,也可以自行调整控制比例的那个函数,又或者重新画一个波浪。
分享到: QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
$\href{https://kuingggg.github.io/}{\text{About Me}}$

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

TOP

返回列表 回复 发帖