将 \tikz\node 定位在正在运行的文本流上,与基线对齐?

将 \tikz\node 定位在正在运行的文本流上,与基线对齐?

在下面的 MWE 中,我希望插入的“y”节点与基线对齐,这样与运行文本的流程没有区别;最后,我想将“X”节点与其中一个“y”节点对齐,同样与基线对齐。然而,我得到的却是这样的:

测试.png

我怎样才能实现“y”节点与单词“yesty”中的对齐方式相同(并且“X”节点与基线处的“y”节点对齐,而不会干扰文本流)?

妇女权利委员会:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}

\tikzstyle{rpo} = [remember picture,overlay]
\tikzstyle{nn} = [inner sep=0pt, outer sep=0pt, minimum size=0pt,anchor=base]
\tikzstyle{nf} = [nn,draw=black]
\tikzstyle{nr} = [nn,draw=red]
\def\tzn{\tikz\node}
\def\tzrn{\tikz[remember picture]\node}
\def\tzon{\tikz[rpo]\node}

\begin{document}

\noindent
Testy yesty  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  Testy  yesty  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy

\noindent
Testy \tzn[nn]{y};esty  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  Testy  \tzn[nf]{y};esty  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy

\noindent
Testy yesty testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  Testy  \tzrn[nf,baseline=(A.base)](A){y};esty  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy

\tzon[nr,draw=red,anchor=base] at (A.base) {X};

\end{document}

答案1

啊,明白了;瞧,我有:

\tzrn[nf,baseline=(A.base)](A){y}

...扩展为:

\tikz[remember picture]\node[nf,baseline=(A.base)](A){y}

...但是,这是错误的,该baseline参数应该应用于\tikz- 而不是应用于\node(这个网站上有一篇关于此问题的帖子,但我丢失了链接)。正确的应该是:

\tikz[remember picture,baseline=(A.base)]\node[nf](A){y}

... 或baseline=0ptbaseline=(current bounding box.base)似乎也有效。所以现在的结果 - 也要注意正确的remember picture(流入文本的节点应该只有这个)和overlay(被覆盖的节点应该同时有两者) - 是这样的:

/测试.png

...使用这个 MWE:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}

\tikzstyle{rpo} = [remember picture,overlay]
\tikzstyle{nn} = [inner sep=0pt, outer sep=0pt, minimum size=0pt,anchor=base]
\tikzstyle{nf} = [nn,draw=black]
\tikzstyle{nr} = [nn,draw=red]
\def\tzn{\tikz\node}
\def\tzrn{\tikz[remember picture]\node}
\def\tzRn{\tikz[remember picture,baseline=(current bounding box.base)]\node}
\def\tzon{\tikz[rpo]\node}

\begin{document}

\noindent
Testy yesty  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  Testy  yesty  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy

\noindent
Testy \tzn[nn]{y};esty  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  Testy  \tzRn[nf]{y};esty  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy

\noindent
Testy yesty testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy  Testy  \tzRn[nf](A){y};esty  testy  testy  testy  testy  testy  testy  testy  testy  testy  testy

\tzon[nr,draw=red,anchor=base] at (A.base) {X};

\end{document}

相关内容