以下代码导致箭头不是从彩色框开始,\ell
而是从彩色框的中心开始。如何解决这个问题?(remember picture
已在序言中定义为包含在每个 tikz 环境中)
\[
x(t) =
\int_0^t
\tikz[baseline]{\node[fill=blue!20,anchor=base] (t3) {$
\tikz[baseline]{\node[inner sep=0pt,outer sep=0pt] (ell) {$\ell$}}
(z)$} }
\, ds
\]
\begin{tikzpicture}[remember picture,overlay]
\draw[black,thick,->] (ell) to [in=90,out=245] +(225:2cm) node[anchor=north,text=black] {instant};
\end{tikzpicture}
答案1
我猜想/怀疑您正在寻找类似这样的东西:
但我不确定。要得到上述结果,您需要至少编译下面的 MWE 三次。
\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{tikzmark} % <---
\tikzset{is/.style = {inner ysep=2pt}}
\begin{document}
\lipsum[1][1-2]
\[
x(t) = \int_0^t \colorbox{blue!20}{$\tikzmarknode[is]{A}{\ell}(z)$}\, ds
\]
\begin{center}
\begin{tikzpicture}[remember picture,overlay]
\draw[thick,->] (A.south) to [in=90,out=245] +(225:12mm) node[anchor=north] {instant};
\end{tikzpicture}
\bigskip
\end{center}
\lipsum[1][3-5]
\end{document}
笔记:请在将来考虑我的评论,并在问题中始终提供 MWE(最小工作示例)!
附录:
为了好玩和展示,你如何将简单的解决方案转变为复杂且容易出错的解决方案:
\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
backgrounds,
fit,
shapes.multipart}
\tikzset{every picture/.append style = {remember picture,baseline},
MN/.style = {rectangle split, rectangle split horizontal,
rectangle split parts=2,
inner xsep=0pt, inner ysep=1pt, anchor=base},
FIT/.style = {fit=#1, fill=cyan!50, inner sep=3pt,
node contents={}},
arr/.style = {-Straight Barb, semithick}
}
\begin{document}
\lipsum[1][1-2]
\[
x(t) = \int_0^t \tikz{\node (ell) [MN] {$\ell$\nodepart{two}$(z)$};
\scoped[on background layer]
\node [FIT=(ell)];
}
\, ds
\]
\begin{center}
\begin{tikzpicture}[overlay]
\draw[arr] (ell.one south)..controls +(0,-1) and + (0,1).. ++ (-1,-1) node[below] {instant};
\end{tikzpicture}
\bigskip
\end{center}
\lipsum[1][3-5]
\end{document}
它在某种程度上类似于@Jasper Habicht 的回答。
答案2
您需要添加remember picture
到环境中tikz
才能引用当前环境之外的节点。但是,您不应该嵌套tikz
环境。这会破坏几件事,其中正确使用坐标定位remember picture
只是其中之一。
Zarko 的答案实际上比下面的更好、更简单,但我仍然想发布这个来向您展示如何使用库fit
(与库结合backgrounds
)来“嵌套”节点。更准确地说,节点不是嵌套的,而是绘制一个足够大的节点来包裹其他节点。如果您真的想使用 Ti 排版蓝色框,这将是创建您尝试的内容的正确方法钾Z:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit, backgrounds}
\begin{document}
\[
x(t) = \int_0^t
\tikz[remember picture, baseline]{
\node[anchor=base, inner sep=0pt] (ell) {$\ell$};
\node[anchor=base west, inner sep=0pt] (z) at (ell.base east) {$(z)$};
\begin{scope}[on background layer]
\node[fill=blue!20, fit={(ell) (z)}] {};
\end{scope}
} \, ds
\]
\begin{tikzpicture}[remember picture, overlay]
\draw[black, thick, ->, shorten <=2pt] (ell.270) to [in=90, out=245] ++(225:2cm) node[anchor=north] {instant};
\end{tikzpicture}
\end{document}