3

Can I do arithmetic on tikzmark points? For example if I have \tikzmark{A} and \tikzmark{B} can I find their midpoint?

1
  • Thanks Marmot! The \tikzmark part of your example works fine, but the \tikzmarknode is an "undefined control sequence" for me, even after reinstalling MacTex/Tex Live. I guess it's in some version of the tikz packege that has not yet been added to the main distribution?
    – tcp
    Dec 26, 2018 at 6:58

1 Answer 1

5

Welcome to TeX.SE! You can use calc for that. In general, the midpoint between a and b is given by ($(a)!0.5!(b)$). One slight subtlety is that you have to prepend pic cs: to the \tikzmark coordinates, but not for \tikzmarknode nodes. The following MWE illustrates this.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc}
\begin{document}
Hello\tikzmark{A} something else\tikzmark{B}.\begin{tikzpicture}[overlay,remember picture]
\draw[red,latex-] ($(pic cs:A)!0.5!(pic cs:B)$) -- ++(0,-1);
\end{tikzpicture} \tikzmarknode{H}{Hello} world and \tikzmarknode{M}{marmots}!\begin{tikzpicture}[overlay,remember picture]
\draw[red,latex-] ($(H)!0.5!(M)$) -- ++(0,-1);
\end{tikzpicture}
\end{document}

enter image description here

1
  • 1
    +1 for the comparison between \tikzmark and \tikzmarknode!
    – CarLaTeX
    Dec 25, 2018 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.