
我試圖定義一個虛線\Uparrow
:我的第一次嘗試,使用tikz
,只是在法線上繪製兩個白色矩形\Uparrow
,手動嘗試找到矩形的良好定位。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\newcommand{\Dasheduparrow}{
\begin{tikzpicture}[x=1, y=1]
\node (0,0) [inner sep=0] {$\Uparrow$};
\fill[fill=white] (-3,0.5) rectangle (2,-1);
\fill[fill=white] (-3,-2) rectangle (2,-3.5);
\end{tikzpicture}}
現在輸入
\begin{document}
Text $\Dasheduparrow$ $\Downarrow$ $\Uparrow$ text.
\end{document}
我明白了
我對輸出非常滿意。不過,我有三個問題:
- 如何獲得法線
\Downarrow
和的相同對齊方式\Uparrow
?我的新符號與文字的基線對齊,而兩個預設符號稍微下移。 - 如何讓這個新符號正確拉伸?透過執行
\LARGE Text $\Dasheduparrow$ $\Downarrow$ $\Uparrow$ text.
輸出,可以明顯看出底層
\Uparrow
已經放大,而白色矩形沒有放大。 - 有比我提出的更好的解決方案嗎?
答案1
修改後的答案
OP 評論說,根據我原來的答案,間隙不會根據不同的字體大小(和數學樣式)進行縮放。這可以透過放棄tikz
並使用我的stackengine
包來解決,同時使用數學樣式縮放間隙大小(使用scalerel
包的\LMex
[Local-Mathstyle ex] 而不是cm
或pt
作為白色矩形覆蓋層的尺寸)。
為了回答OP的另一個問題,\ThisStyle{...\SavedStyle...}
語法允許將當前的數學樣式帶入通常會丟失的結構中,在這種情況下,進入\hbox
正在\vcenter
編輯和堆疊的結構中。它相當於一個美化的\mathchoice
,但通常會大大減少所需的打字量。
\documentclass{article}
\usepackage[utf8]{inputenc}
%\usepackage[T1]{fontenc}
\usepackage{scalerel,stackengine,xcolor}
\newcommand{\Dasheduparrow}{\ThisStyle{\vcenter{\hbox{$%
\stackengine{0.45\LMex}{\stackengine{-.15\LMex}{$\SavedStyle\Uparrow$}
{\textcolor{white}{\rule{1.1\LMex}{0.3\LMex}}}{O}{c}{F}{T}{L}%
}{\textcolor{white}{\rule{1.1\LMex}{0.3\LMex}}}{O}{c}{F}{T}{L}%
$}}}}
\begin{document}
Text $\Dasheduparrow$ $\Downarrow$ $\Uparrow$ text.
$\Dasheduparrow \scriptstyle \Dasheduparrow \scriptscriptstyle \Dasheduparrow$
\LARGE
Text $\Dasheduparrow$ $\Downarrow$ $\Uparrow$ text.
\end{document}
原答案
在這裡,我從 OP 的定義開始。
但是,我隨後將\vcenter
其置於數學軸的中心,並使用scalerel
功能來保留數學風格。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{scalerel}
\newcommand{\Dasheduparrow}{\ThisStyle{\vcenter{\hbox{$
\begin{tikzpicture}[x=1, y=1]
\node (0,0) [inner sep=0] {$\SavedStyle\Uparrow$};
\fill[fill=white] (-3,0.5) rectangle (2,-1);
\fill[fill=white] (-3,-2) rectangle (2,-3.5);
\end{tikzpicture}$}}}}
\begin{document}
Text $\Dasheduparrow$ $\Downarrow$ $\Uparrow$ text.
$\Dasheduparrow \scriptstyle \Dasheduparrow \scriptscriptstyle \Dasheduparrow$
\end{document}
答案2
快速解決方法(可能有點不乾淨):
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz,calc}
\newcommand{\Dasheduparrow}{
\begin{tikzpicture}[x=1, y=1]
\node (0,0) [inner sep=0] {$\Uparrow$};
\fill[fill=white] (-3,0.5) rectangle (2,-1);
\fill[fill=white] (-3,-2) rectangle (2,-3.5);
\end{tikzpicture}}
\begin{document}
Text \parbox{\widthof{$\Dasheduparrow$}}{$\Dasheduparrow$} $\Downarrow$ $\Uparrow$ text.
\end{document}
我使用 a 來parbox
居中其內容。
\parbox{\widthof{$\Dasheduparrow$}}{$\Dasheduparrow$}
另一種可能性是使用數學居中命令:
\vcenter{\hbox{\Dasheduparrow}}