2

The following code, adapted from the first answer here , works the way I want.

But it is not what I expected. I'm reusing the tikzmark labels a..e, and the \makebrace use after the first placement of the marks uses those placements, and the use after the second placement uses the second placements.

Can I depend on this behavior? If not, is there a way to localize tikzmarks?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc,tikzmark}
\newcommand{\ntkm}[2]{#2\thinspace\tikzmarknode{#1}{}}
% #1 top item; #2 bottom item; #3 widest item; #4 text
\newcommand{\makebrace}[4]{%
    \begin{tikzpicture}[overlay, remember picture]
        \draw [decoration={brace,amplitude=0.5em},decorate,line width=0.09em]
        let \p1=(#1), \p2=(#2), \p3=(#3) in
        ({\x3+1em}, {\y1+0.9em}) -- node[right=0.6em] {#4} ({\x3+1em}, {\y2-0.2em});
    \end{tikzpicture}
}

\begin{document} \begin{itemize} \item \ntkm{a}{{This is item one of first list}} \item \ntkm{b}{{This is item two of first list}} \item \ntkm{c}{{This is item three of first list}} \item \ntkm{d}{{This is item four of first list}} \item \ntkm{e}{{This is item five of first list}} \end{itemize} \makebrace{a}{b}{c}{First two items} \makebrace{c}{e}{c}{Other items}

% much later in long document ... \begin{itemize} \item \ntkm{a}{{This is item one of second list}} \item \ntkm{b}{{This is item two of second list}} \item \ntkm{c}{{This is item three of second list}} \item \ntkm{d}{{This is item four of second list}} \item \ntkm{e}{{This is item five of second list}} \end{itemize} \makebrace{a}{b}{c}{First two items of second list} \makebrace{c}{e}{c}{Other items of second list} \end{document}

dedded
  • 2,236

1 Answers1

1

TL; DR Yes, and yes.


You are actually using \tikzmarknode which defines both nodes and marks. In the code that draws the braces you are using the nodes, not the marks. Nodes are defined in-document, so the \tikzmarknode defines a node that can then be used, and a subsequent \tikzmarknode overwrites it and so after the second use then the first is forgotten and the second is then available from then on. This is the expected behaviour when using nodes.

Were you to use the marks in the brace code, you would run into issues with re-use because marks are saved to the aux file and so it's a case of "last mark wins" - the last version of a mark is read back into the document at its start and is the only one available. However, in this case then there is a way to make tikzmarks unique without needing to change the apparent names in the code. It is possible to define a prefix and a suffix that are automatically added to tikzmark names. So by defining one or both of these around each list, you can localise the names. See the documentation for details on setting these.

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751