获取 tikzmark 的位置

获取 tikzmark 的位置

为了解决这个问题,我想获得ya 的绝对位置tikzmark(实际上我想要的是与文本区域边框的距离,但我想在这两个值之间转换并不难。目标是将它与此解决方案)。但我不知道该怎么做,有什么想法吗?

\documentclass[a4paper,12pt]{book}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc,tikzmark}
\usepackage{lipsum}
\usepackage{showframe}
\usepackage{everypage}
\usepackage{changepage}

\begin{document}

\noindent Here is some text.

\begin{adjustwidth}{1cm}{-8em}
  \noindent \tikzmark{hello}Hello. \message{Horizontal distance from border is ???}
\end{adjustwidth}

\end{document}

答案1

\documentclass[a4paper,12pt]{book}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc,tikzmark}
\usepackage{lipsum}
\usepackage{showframe}
\usepackage{everypage}
\usepackage{changepage}
\begin{document}
\noindent Here is some text.
\begin{adjustwidth}{1cm}{-8em}
  \noindent \tikzmark{hello}Hello. \message{Horizontal distance from border is ???}
\end{adjustwidth}
\begin{tikzpicture}[overlay, remember picture, shift=(current page.north west)]
\draw[red] let \p1=(pic cs:hello) in (\x1,\y1) -| (current page.north) node[right, pos=0.75] {\y1 \xdef\mydim{\y1}};
\end{tikzpicture}
\mydim
\end{document}

带有框架和距离的页面

相关内容