7

A tikzmarknode combined with a vphantom character takes up horizontal space. Minimal but nonetheless noticeable.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
Text \tikzmarknode{a}text

Text \tikzmarknode{b}text
\begin{tikzpicture}[remember picture,overlay]  \draw (a.west) -- (b.west); \end{tikzpicture}

Text \tikzmarknode{a}{\vphantom{t}}text

Text \tikzmarknode{b}{\vphantom{t}}text
\begin{tikzpicture}[remember picture,overlay]  \draw (a.west) -- (b.west); \end{tikzpicture}
\end{document}

enter image description here

Anyone able to explain why? And is there a way to either prevent that or at least to figure out what the exact space is so I can fix it somehow?

  • The problem is not the \vphantom, but that the argument has not width. Compare with \tikzmarknode{a}{} instead of leaving out the second argument (which then picks up the t). – Ulrike Fischer Apr 6 at 9:45
  • @UlrikeFischer I don't quite understand. Both {} and the vphantom give me the little extra space. My goal of using vphantom was to control the vertical anchor "west" of the node, without using up horizontal space. – jan Apr 6 at 9:57
  • Yes as I said, both cases introduce a 1pt box. But I don't have the time to look now why, perhaps later. – Ulrike Fischer Apr 6 at 9:59
  • @UlrikeFischer thank you! – jan Apr 6 at 10:05
  • @UlrikeFischer If you are sure it's always exactly 1pt, I could control for it with a negative hspace? ... but still curious as to what exactly is going on here. – jan Apr 6 at 10:21
8

The problem is minimum width which has the value 1pt (the documentation seems to be wrong here). Probably tikzmark should better set it to 0pt in the \tikzmarknode, make a bug report.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{every tikzmarknode/.style={minimum width=0pt}}
\begin{document}
\pgfkeysvalueof{/pgf/minimum width}

Text \tikzmarknode{a}text

Text \tikzmarknode{b}text
\begin{tikzpicture}[remember picture,overlay]  \draw (a.west) -- (b.west); \end{tikzpicture}

Text \tikzmarknode{a}{\vphantom{t}}text

Text \tikzmarknode{b}{\vphantom{t}}text
\begin{tikzpicture}[remember picture,overlay]  \draw (a.west) -- (b.west); \end{tikzpicture}
\end{document}

enter image description here

  • I've submitted a bugreport on github, thank you :) – jan Apr 6 at 12:57
  • The default of 1pt for minimum width is set in the TikZ/pgf code, not the tikzmark code. tikzmark doesn't explicitly set minimum width. Do you think that it ought to? This feels like an edge case in that usually \tikzmarknode will have some contents, and thus some width. That said, it does explicitly set inner sep to 0pt so for consistency perhaps there's a case for minimum width to be explicitly set to 0pt and then every tikzmarknode/.style used to override that. I'm not sure which way to go here. – Loop Space Apr 6 at 17:38
  • @LoopSpace imho it would be sensible if tikzmarknode would set locally minimum width to 0pt. 1pt doesn't make sense. – Ulrike Fischer Apr 6 at 21:45
  • I agree that if I'm to set it in \tikzmarknode then 0pt makes more sense than 1pt. I'm just not sure that there's a case for \tikzmarknode to set it at all. – Loop Space Apr 6 at 22:00
  • 1
    @LoopSpace the example here is a case: I can't see who would expect a \tikzmarknode with an empty argument to give an 1pt box. – Ulrike Fischer Apr 6 at 22:11

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.