8

I want to a sequence of nodes, finished by a line. I tried this:

\documentclass{article}
\usepackage{tikz}
\tikzstyle{st1}=[circle, inner sep=1.5pt, draw]
\tikzstyle{st2}=[rectangle, inner xsep=2pt, inner ysep=0pt, draw] 
\begin{document}
    \begin{tikzpicture}[grow=down, level distance=10pt, every node/.style={st1}]
        \path node{} child {node{} child {node[st2]{}}};
    \end{tikzpicture}
\end{document}

but this gives TikZ_ex_nodes_v1, i.e. the node has some height. Is there some (simple) way to make the last node into a line? If possible using definition of st2, so it it simple to use.

The closest thing I managed is:

\documentclass{article}
\usepackage{tikz}
\tikzstyle{st1}=[circle, inner sep=1.5pt, draw]
\tikzset{st2/.style={rectangle, inner sep=-2pt, draw=none}}
\begin{document}
    \begin{tikzpicture}[grow=down, level distance=10pt, every node/.style={st1}]
        \path node{} child {node{} child {node[st2]{\textbf{--}}}};
    \end{tikzpicture}
\end{document}

but this is more a dirty hack. In addition, it needs needs having \textbf{--} in every such node .. and it won't work if I ever need the sequence to be horizontal.

Thanks.

1 Answers1

9

The key is to give a minimum height to that node. Here you can see the result with 0pt and .4pt respectively:

Result

UPDATE: Also, in order to get a better control of the width of the node, use minimum width instead of inner xsep. Analogously, you better use minimum width for the circular nodes too, instead of inner sep=1.5pt. This way you can play with the size of the nodes, as for example:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzstyle{st1}=[circle, inner sep=0pt, minimum width=4pt, draw]
\tikzstyle{st2}=[rectangle, inner sep=0pt, minimum height=0pt, minimum width=4pt, draw] 

\tikzstyle{st1b}=[circle, inner sep=0pt, minimum width=6pt, draw]
\tikzstyle{st2b}=[rectangle, minimum height=.4pt, minimum width=6pt, inner sep=0pt, draw] 

\begin{tikzpicture}[grow=down, level distance=10pt, every node/.style={st1}]
        \path node{} child {node{} child {node[st2]{}}};
\end{tikzpicture}
\begin{tikzpicture}[grow=down, level distance=10pt, every node/.style={st1b}]
        \path node{} child {node{} child {node[st2b]{}}};
\end{tikzpicture}
\end{document}

Which produces:

enter image description here

JLDiaz
  • 55,732