使用 tikz 帶箭頭下劃線

使用 tikz 帶箭頭下劃線

我想用箭頭(來自 tikz)在數學物件下劃線,而不在跳行中添加額外的空間,就像這樣

The object C has an underline with an arrowhead
from tikz. The only problem  is the extra space
between the lines.

目前,我正在使用以下程式碼(MWE)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows,decorations.markings}
\newcommand{\subtodisplay}{%
  {\tikz[baseline=-2ex] \draw[-stealth,line width=.4pt] (.3ex,0ex) -- (1.7ex,0ex);}
}

\begin{document}
The object $\mathop{C}\limits_{\subtodisplay}$ has an underline with an 
arrowhead from tikz. The only problem is the extra space between the lines,
which becomes apparent when adding extra text to get at least three lines.
\end{document}

下標/上標的額外空間對我來說通常是一個問題。有沒有辦法強制行間距?顯然在這種情況下不需要額外的空間:

帶箭頭的底線

(我通常只需要它來給單個字母下劃線,因此大小可以是固定的,儘管我歡迎一個可以使用可變寬度的答案。)

答案1

為什麼不使用 \underrightarrow 指令呢?例如這樣:

\underrightarrow{\mho}

獲得:

底線箭頭姆歐

您也可以為多個字母/表達式新增底線:

\underrightarrow{\mho+\sum^{n}_{i=1}K=0+\Psi}

底線表達

但你不會經常將它與多個字母一起使用

答案2

這是一種可能的解決方案:

\documentclass[varwidth,border=50]{standalone}
\usepackage{tikz}
\usepackage{blindtext}

\newcommand{\tikzunderarrow}[2][red]{\tikz[baseline={(N.base)}]{
  \node[inner sep=0, outer sep=0](N) {#2};
  \draw[overlay, -latex, line width=.04em, #1]
    ([yshift=-.14em]N.south west) -- ([yshift=-.14em]N.south east);}}

\begin{document}
  A test sentence : \tikzunderarrow{ypqj to ckeck if it is ok ;)}.
  \blindtext

  And we check with math formula \tikzunderarrow{$\left[ \sqrt{x^2+y^2} \right]$},
  and a {\Large \tikzunderarrow[purple,|-stealth]{Large}} underarrow.
\end{document}

在此輸入影像描述

編輯:根據 Peter Grill 的建議,我添加了overlay保持垂直尺寸等於節點中文字的尺寸。

編輯2:我添加了一些點字來表明垂直距離是可以的。

編輯3:根據 Paul Gaborit 和 Earthliŋ 的建議,我將其替換inner xsep=0inner sep=0.現在這個答案是一個社區維基。

編輯4:現在我們可以將箭頭樣式變更為可選參數。

相關內容