1

In order to solve this question, I'd like to obtain the absolute y position of a tikzmark (actually I want the distance from the border of the text area, but I guess it's not too hard to convert between these two values. The goal is to combine it with this solution). But I can't find how to do, any idea?

\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}

tobiasBora
  • 8,684

1 Answers1

2
\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}

Page with frames and a distance

  • Thanks. I was not expecting this solution to work when using it on different pages, but it seems to work. However is it possible to store the result of the let in a macro? – tobiasBora Nov 17 '21 at 14:18
  • 1
    I do not know if there are better ways - also dependent on if it needs to be used outside TikZ: \draw[red] let \p1=(pic cs:hello) in (\x1,\y1) -| (current page.north) node[right, pos=0.75] {\y1 \xdef\mydim{\y1}}; stores in \mydim. – hpekristiansen Nov 17 '21 at 14:46
  • Oh that's a funny method ^^ – tobiasBora Nov 17 '21 at 14:49