Tikz 在 (基线 + 西南) 处绘制

Tikz 在 (基线 + 西南) 处绘制

如果我跑步\test{ap}并且\test{ap}得到

在此处输入图片描述

以下是代码

\newcommand{\test}[1]{
\tikz[baseline=(arced node.base)]{
            \node [inner sep=0pt, outer sep=0pt] (arced node) {#1};
            \draw [line width=2pt,transform canvas={yshift=-0.5mm},color=black] (arced node.south west) parabola [parabola height=-1.5mm] (arced node.south east);
        }
}

我希望两条抛物线的高度相同。要么从基线开始,要么从深度开始。你们知道如何做到这一点吗?

答案1

我相信你正在寻找base west锚点。

\documentclass{article}

\usepackage{tikz}

\newcommand{\test}[1]{
  \tikz [baseline=(arced node.base)] {
    \node [inner sep=0pt, outer sep=0pt] (arced node) {#1};
    \draw [line width=2pt,transform canvas={yshift=-0.5mm},color=black] (arced node.base west) parabola [parabola height=-1.5mm] (arced node.base east);
  }
}

\begin{document}

ab \test{ab} \test{ap} ap

\end{document}

MWE 输出

答案2

当某些后代(?)缺失时,调整垂直对齐的其他一些替代方法。包括\strut或一个\vphantom或只是一个text depth进入节点的定义。

绘制节点以查看每个选项对其大小的影响。对齐正确且south使用了锚点。

\documentclass{article}

\usepackage{tikz}

\newcommand{\test}[1]{
  \tikz [baseline=(arced node.base)] {
    \node [inner sep=0pt, outer sep=0pt, draw] (arced node) {#1\strut};
    \draw [line width=2pt,transform canvas={yshift=-0.5mm},color=black] (arced node.south west) parabola [parabola height=-1.5mm] (arced node.south east);
  }
}

\newcommand{\testa}[1]{
  \tikz [baseline=(arced node.base)] {
    \node [inner sep=0pt, outer sep=0pt, draw] (arced node) {#1\vphantom{p}};
    \draw [line width=2pt,transform canvas={yshift=-0.5mm},color=black] (arced node.south west) parabola [parabola height=-1.5mm] (arced node.south east);
  }
}

\newcommand{\testb}[1]{
  \tikz [baseline=(arced node.base)] {
    \node [inner sep=0pt, outer sep=0pt, draw, text depth=.25ex] (arced node) {#1};
    \draw [line width=2pt,transform canvas={yshift=-0.5mm},color=black] (arced node.south west) parabola [parabola height=-1.5mm] (arced node.south east);
  }
}

\begin{document}

ab \test{ab} \test{ap} ap \testa{ab} \testa{ap} ap \testa{ab} \testa{ap}

\end{document}

在此处输入图片描述

相关内容