4

Please consider my minimal example. I would like to place an additional element -in this case a text field- in the middle of the line between nodes A and B. How does this work?

Which of the following commands would be the correct one here?

  1. append after command={...},
  2. node contens={...},
  3. code={...} or path picture={...}

Minimalbeispiel:

 \documentclass[tikz]{standalone}
    \usetikzlibrary{positioning, calc, fit, shadings, shadows, shapes.arrows, arrows.meta, matrix, mindmap}
    \usepackage{hyperref}
    \begin{document}
    \begin{tikzpicture}[
        textfield extension/.style ={
            rounded corners, 
            arrows={-Straight Barb[angle=60:9pt 3]},
            append after command={
                node[circle, fill=red] {\TextField[name=1,width=3cm,height=1em,multiline=false,bordercolor=black, charsize=9pt]{}}
            }
        }]
        \node(A) [circle, fill=red] at (0,0){A};
        \node(B) [circle, fill=red] at (10,0){B};
        \draw[solid, black, textfield extension] (A) -- (B);
    \end{tikzpicture}
    \end{document}
0

4 Answers 4

3

You could try the insert path option together with the calc library, but it would be semantically better to use a to node.

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, calc}

\usepackage{hyperref}

\begin{document}
\begin{tikzpicture}[
    textfield extension/.style args={#1 and #2}{
        rounded corners, 
        arrows={-Straight Barb[angle=60:9pt 3]},
        insert path={
            node[circle, fill=red] at ($(#1)!.5!(#2)$) {\TextField[name=1,width=3cm,height=1em,multiline=false,bordercolor=black, charsize=9pt]{}}
        }
    }]
    \node(A) [circle, fill=red] at (0,0){A};
    \node(B) [circle, fill=red] at (10,0){B};
    \draw[solid, black, textfield extension={A and B}] (A) -- (B);
\end{tikzpicture}
\end{document}

\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{arrows.meta}

\usepackage{hyperref}

\begin{document}
\begin{tikzpicture}[
    extension line/.style={
        rounded corners, 
        arrows={-Straight Barb[angle=60:9pt 3]},
    }]
    \node(A) [circle, fill=red] at (0,0){A};
    \node(B) [circle, fill=red] at (10,0){B};
    \draw[solid, black, extension line] 
        (A) -- 
        node[midway, circle, fill=red]  {\TextField[name=1,width=3cm,height=1em,multiline=false,bordercolor=black, charsize=9pt]{}} 
        (B);
\end{tikzpicture}
\end{document}

enter image description here

4

I'm not sure if I understood correctly your problem. To me is unclear, why you need textfield extension. Just inserting a text in node at middle of the arrow between nodes A and B is not needed.

To my opinion the simplest way doing what you say in question title is:

\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{arrows.meta}
\usepackage{hyperref}

\begin{document}
\begin{tikzpicture}[
    C/.style = {circle, fill=red, minimum size=\nodewidth,
                append after command = {
                    node[draw, semithick, fill=white, font=\small,
                         minimum width=\nodewidth-8pt] {#1}
                                        }
                }
                    ]
\def\nodewidth{22mm}
\node (A) [circle, fill=red]            {A};
\node (B) [circle, fill=red] at (10,0)  {B};
\draw[-{Straight Barb[angle=60:9pt 3]}, semithick]
        (A) --  node[C=text] {} (B);
\end{tikzpicture}
\end{document}

enter image description here

If I misunderstood your question than please edit it and more clear explain what is your problem.

2

I would use a normal node command:

\documentclass[tikz]{standalone}
    \usetikzlibrary{positioning, calc, fit, shadings, shadows, shapes.arrows, arrows.meta, matrix, mindmap}
    \usepackage{hyperref}
    \begin{document}
    \Form
    \begin{tikzpicture}[
        textfield extension/.style ={
            rounded corners,
            arrows={-Straight Barb[angle=60:9pt 3]},
        }]
        \node(A) [circle, fill=red] at (0,0){A};
        \node(B) [circle, fill=red] at (10,0){B};
        \draw[solid, black, textfield extension] (A) -- (B);
        \node[circle,fill=red,above] at ($(A)!0.5!(B)$) {\TextField[name=1,width=3cm,height=1em,multiline=false,bordercolor=black, charsize=9pt]{}};
    \end{tikzpicture}
    \end{document}

enter image description here

2

You can't place a node automatically along a -- path. This only works by writing the node in the path directly.

There's insert path but you can't use this anywhere and especially not after --:

\tikz\draw (0,0) -- (2,1) [insert path={node[midway]{a}}];

If you want to place nodes via a style, you'll need either the to or the edge path operator. Then you can set nodes along that path with edge node. (The quotes extends that functionality for easier input.)

To make the following examples shorter, I've defined:

\tikzset{
  every textfield extension/.style={
    rounded corners, arrows={-Straight Barb[angle=60:9pt 3]}},
  my edge node/.style={
    edge node={node[midway,circle,fill=red]{
        \TextField[name=1,width=3cm,height=1em,multiline=false,bordercolor=black, charsize=9pt]{}
      }
    }
  }
}

The definition of textfield extension then is dependent on how you want to use the style.

If you want to use to and a \path[textfield extension] declaration you'll want to append that edge node to every to:

\begin{tikzpicture}[
  textfield extension/.style={every textfield extension, every to/.append style=my edge node}]
\node(A) [circle, fill=red] at (0,0){A};
\node(B) [circle, fill=red] at (10,0){B};
\draw[solid, black, textfield extension] (A) to (B) to[bend left=90] (A);
\end{tikzpicture}

For edge and a \path[textfield extension] declaration you'll want to append that edge node to every edge:

\begin{tikzpicture}[
  textfield extension/.style={every textfield extension,every edge/.append style=my edge node}]
\node(A) [circle, fill=red] at (0,0){A};
\node(B) [circle, fill=red] at (10,0){B};
\path[solid, black, textfield extension] (A) edge (B)
                                         (B) edge[bend left=90] (A);
\end{tikzpicture}

Both these solutions place the nodes along both tos/edges while to treats both connections as one path and only places one arrow head and edge constructs two separate paths, thus two arrow heads.

However, since this looks like a style that's only to be used with connection between nodes, i.e. edges, I'll use it this way:

\begin{tikzpicture}[
  textfield extension/.style={every textfield extension, my edge node}]
\node(A) [circle, fill=red] at (0,0){A};
\node(B) [circle, fill=red] at (10,0){B};
\path[solid, black] (A) edge[textfield extension] (B)
                    (B) edge[bend left=90] (A);
\end{tikzpicture}

If you still want this style to be applied to multiple edges on one path, I'll suggest defining edges/.style={every edge/.append style={#1}} and then:

\begin{tikzpicture}[
  edges/.style={every edge/.append style={#1}},
  textfield extension/.style={every textfield extension, my edge node}]
\node(A) [circle, fill=red] at (0,0){A};
\node(B) [circle, fill=red] at (10,0){B};
\node(C) [circle, fill=red] at (0,10){C};
\path[solid, black, edges=textfield extension] (A) edge (B)
                                                   edge (C);
\end{tikzpicture}

I've also added a insert path solution, I don't know if that is a better user interface, though.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta}
\usepackage{hyperref}
\tikzset{
  every textfield extension/.style={
    rounded corners, arrows={-Straight Barb[angle=60:9pt 3]}},
  my edge node/.style={
    edge node={node[midway,circle,fill=red]{
        \TextField[name=1,width=3cm,height=1em,multiline=false,bordercolor=black, charsize=9pt]{}
      }
    }
  }
}
\begin{document}
\begin{tikzpicture}[
  textfield extension/.style={every textfield extension, every to/.append style=my edge node}]
\node(A) [circle, fill=red] at (0,0){A};
\node(B) [circle, fill=red] at (10,0){B};
\draw[solid, black, textfield extension] (A) to (B) to[bend left=90] (A);
\end{tikzpicture}
\begin{tikzpicture}[
  textfield extension/.style={every textfield extension, every edge/.append style=my edge node}]
\node(A) [circle, fill=red] at (0,0){A};
\node(B) [circle, fill=red] at (10,0){B};
\path[solid, black, textfield extension] (A) edge (B)
                                         (B) edge[bend left=90] (A);
\end{tikzpicture}
\begin{tikzpicture}[
  textfield extension/.style={every textfield extension, my edge node}]
\node(A) [circle, fill=red] at (0,0){A};
\node(B) [circle, fill=red] at (10,0){B};
\path[solid, black] (A) edge[textfield extension] (B)
                    (B) edge[bend left=90] (A);
\end{tikzpicture}
\begin{tikzpicture}[
  edges/.style={every edge/.append style={#1}},
  textfield extension/.style={every textfield extension, my edge node}]
\node(A) [circle, fill=red] at (0,0){A};
\node(B) [circle, fill=red] at (10,0){B};
\node(C) [circle, fill=red] at (0,10){C};
\path[solid, black, edges=textfield extension] (A) edge (B)
                                                   edge (C);
\end{tikzpicture}
\begin{tikzpicture}[
  textfield extension path/.style args={#1to#2}{
    insert path={#1 edge[textfield extension] #2}},
  edges/.style={every edge/.append style={#1}},
  textfield extension/.style={every textfield extension, my edge node}]
\node(A) [circle, fill=red] at (0,0){A};
\node(B) [circle, fill=red] at (10,0){B};
\node(C) [circle, fill=red] at (0,10){C};
\path[solid, black] [textfield extension path=(A) to (B), textfield extension path=(C) to (B)];
\end{tikzpicture}
\end{document}

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.