8

I want to create a node within a node. My MWE is as follows.

 \documentclass{article}
 \usepackage{tikz,amsmath,siunitx}
 \usetikzlibrary{tikzmark}
 \begin{document}
   \[\text{a}_{\text{C}} = 0.35\tikzmark{a}7\,\si{\nano\meter}, \tikzmark{b}\text{a}_{\text{Ge}} = \SI{0.5658}{\nano\meter}, \text{ and} \tikzmark{c}\text{ a}_{\text{Si}} = \SI{0.5431}{\nano\meter}.
    \begin{tikzpicture}[overlay,remember picture]
    \draw[<->] ([shift={(0.08,-0.05)}]pic cs:b) -- +(0,-0.3)  node[below,shift={(2,-0.02)},outer sep=0] (d) {$\substack{\text{closer to each other} \\ \text{than a\textsubscript{C} is to} \\ \text{a\textsubscript{Ge} and a\textsubscript{Si}}}$} -|  ([shift={(0.2,-0.05)}]pic cs:c);
    \draw[->] (d) to[bend left] (pic cs:a);
    \end{tikzpicture}\]
 \end{document} 

The result so far is as follows code_output I want to connect the a_C in the substack to the value of a_C in the inline text. Is there a way to define a_C as a node within the parent node (d) and then connect node (d) to node (a).

Thanks for your help!

2 Answers 2

5

tikzmark provides \subnode{}{} for use within nodes in a picture. Unlike marks created with \tikzmark{}, these marks can be referred to directly by name - that is, you do not need to specify the pic coordinate system in order to refer to them.

Hence, you can simply say

\documentclass{article}
\usepackage{amsmath,tikz,siunitx}
\usetikzlibrary{tikzmark}
\begin{document}
\[
  \text{a}_{\text{C}} = 0.35\tikzmark{a}7\,\si{\nano\meter}, \tikzmark{b}\text{a}_{\text{Ge}} = \SI{0.5658}{\nano\meter}, \text{ and} \tikzmark{c}\text{ a}_{\text{Si}} = \SI{0.5431}{\nano\meter}.
  \begin{tikzpicture}[overlay,remember picture]
    \draw[<->] ([shift={(0.08,-0.05)}]pic cs:b) -- +(0,-0.3)  node[below,shift={(2,-0.02)},outer sep=0] (d) {$\substack{\text{closer to each other} \\ \text{than \subnode{ind}{a\textsubscript{C}} is to} \\ \text{a\textsubscript{Ge} and a\textsubscript{Si}}}$} -|  ([shift={(0.2,-0.05)}]pic cs:c);
    \draw[->] (ind) to[bend left] (pic cs:a);
  \end{tikzpicture}
\]
\end{document}

connect sub-node to node

I do wonder if your code is not rather an abuse of maths mode since most of your content is then enclosed in \text{}. This makes it harder to keep the spacing consistent, for example.

Why not something simpler?

\documentclass{article}
\usepackage{tikz,siunitx}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{center}
  a\textsubscript{C}$ = 0.35\tikzmark{a}7\,$\si{\nano\meter}, \tikzmark{b}a\textsubscript{Ge}$ = $\SI{0.5658}{\nano\meter}, and\tikzmark{c} a\textsubscript{Si}$ = $\SI{0.5431}{\nano\meter}.
  \begin{tikzpicture}[overlay,remember picture]
    \draw[<->] ([shift={(0.08,-0.05)}]pic cs:b) -- +(0,-0.3) -| ([shift={(0.2,-0.05)}]pic cs:c) node [pos=.25, below, anchor=north, align=center] (d) {closer to each other\\than \subnode{ind}{a\textsubscript{C}} is to\\a\textsubscript{Ge} and a\textsubscript{Si}};
    \draw[->] (ind) to [bend left=45] (pic cs:a);
  \end{tikzpicture}
\end{center}
\end{document}

possibly simpler

I don't know if this is really correct, but it is at least a bit easier to read the code and the spacing seems better to me - the extra line spacing is useful if you want to draw arrows between lines, for example, and this adds in a missing space following a comma.

2
  • Thanks a lot @cfr! The subnode works like a charm. And I agree I was pushing the [] environment a little too much in this example. Commented Nov 12, 2016 at 22:53
  • @scorpionwars You're welcome! You might consider accepting the answer which helps you most by clicking on the greyed-out tick at the top left of the relevant answer. But don't do this yet if you are hoping for a better answer as people may not look at questions marked as 'solved'.
    – cfr
    Commented Nov 12, 2016 at 23:18
3

Nesting of TikZ pictures is evil ... but with manual tweaking of bend line coordinates and rearrange of text in node you can obtain (without nesting of nodes):

enter image description here

\documentclass{article}
\usepackage{tikz,amsmath,siunitx}
\usetikzlibrary{tikzmark}
    \begin{document}
\[
\tikzmark{a}\mathrm{a}_{\mathrm{C}}  = \SI{0.357}{\nano\meter}, \tikzmark{b}\mathrm{a}_{\mathrm{Ge}} = \SI{0.5658}{\nano\meter}, 
    \text{ and } 
\tikzmark{c}\mathrm{a}_{\mathrm{Si}} = \SI{0.5431}{\nano\meter}.
    \begin{tikzpicture}[overlay,remember picture]
\draw[<->]  ([shift={(0.08,-0.05)}]pic cs:b) -- +(0,-0.3) -| 
            ([shift={(0.08,-0.05)}]pic cs:c)
    node[pos=0.25, below,font=\footnotesize,align=center] (d) 
        {closer to each other than\\ 
         a\textsubscript{C} is to a\textsubscript{Ge} and a\textsubscript{Si}};
    \draw[->] ([shift={(2.5ex,-1.2ex)}]d.west) to[out=180, in=300] ([shift={(0.08,-0.05)}]pic cs:a);
    \end{tikzpicture}\]
 \end{document}
2
  • This really isn't necessary, you know ;).
    – cfr
    Commented Nov 12, 2016 at 0:15
  • @cfr, I wasn't aware for \subnode{}{}, so tank you for your answer and comment to pointed me on it! Of course with it the solution is (slightly :) ) simpler than mine ...
    – Zarko
    Commented Nov 12, 2016 at 0:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .