0

I want to create a diagram on tikz-qtree that look something like this:

enter image description here

Where "alt", "a", and "s" are aligned at the base, and "R", "AF", and "AF" are also aligned at the base (note that I removed the last edge before the leaves; I need it this way).

My first attempt aligned "s" with the higher node (its sister node):

\documentclass{standalone}

\usepackage{tikz}
\usepackage{tikz-qtree}
\tikzset{every tree node/.style={align=center,anchor=base},
    frontier/.style={distance from root=80pt}
}

\begin{document}
    
    \begin{tikzpicture}
        
        \Tree
        [.Adj
            [.Adj
                [.alt\\R-Adj ]
                [.a\\AF-G ] ]
            [.s\\AF-N ] ]

    \end{tikzpicture}

\end{document}

enter image description here

Then I tried adding another node before "s" to make "s" be a sister of "alt" and "a". However, The line between the top "Adj" and "s" is broken and doesn't look elegant.

\documentclass{standalone}

\usepackage{tikz}
\usepackage{tikz-qtree}
\tikzset{every tree node/.style={align=center,anchor=base},
    frontier/.style={distance from root=80pt}
}

\begin{document}
    
    \begin{tikzpicture}
        
        \Tree
        [.Adj
            [.Adj
                [.alt\\R ]
                [.a\\AF ] ]
        [.\node[shape=coordinate] {};  %removes the space (gap) between the edges 
            [.s\\AF ] ]]

    \end{tikzpicture}

\end{document}

enter image description here

Regarding my issue, I have two questions: (1) how can I set my code so that the right-most line goes straight from "Alt" to "s" without the break in between while still keeping "alt", "a", and "s" aligned at the base? And (2), how can I make the edges (ie, the lines) below each "Adj" be the same length without changing to anchor=north? Changing the anchor to north misaligns my nodes because the letter "l" is taller than "a" and "s" in the sister nodes.

2 Answers 2

2

With forest package is simple (for me, since I'm a bit more familiar with it than with tikz-qtree) :

\documentclass[border=3.141592]{standalone}
\usepackage{forest}

\begin{document}
    \begin{forest}
for tree = {
% nodes styles
       align = center,
        font = \linespread{0.84}\selectfont,
   inner sep = 1pt,
% tree style
parent anchor = south,
 child anchor = north,
if n={1}{l sep=3mm,s sep=1mm}{l sep=6mm, s sep=4mm}
            
                }
%
[Adj
    [Adj,
        [alt\\R]
        [a\\AF, tier=L2]
    ]
    [s\\AF,  tier=L2]
]
    \end{forest}
\end{document}

enter image description here

Edit (1):

or would rather have the next tree with edges fixed angles and without nodes on the top of tree.

Edit (2):

Original example using standalone document class is now adopted to ˙beamer`. By this is show, that image is independent from used document class:

enter image description here

\documentclass{beamer}
\usepackage{forest}

\begin{document}
\begin{frame}
\frametitle{Tree drawn by \texttt{forest} package}
\center
    \begin{forest}
for tree = {
% nodes styles
       align = center,
        font = \linespread{0.84}\selectfont,
   inner sep = 1pt,
% tree with fixed angles of edges
      calign = fixed edge angles,
calign angle = 30,       
                }
%
[,coordinate
    [Adj,
        [alt\\R]
        [a\\AF, tier=L]
    ]
    [s\\AF,  tier=L]
]
    \end{forest}
\end{frame}
\end{document}

Addendum: If you prefer (for some reason) to use tikz-qtree package to drawn your trees and willing to do manual adjustment for nodes positioning, than you may consider the following solution which to some degree simplified defining levels distances at nodes positioning:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-qtree}
\newlength{\LD}
                        

\begin{document}
    \begin{tikzpicture}
\pgfmathsetlength\LD{7mm}
\tikzset{
          nodes = {inner sep=2pt, align=center,anchor=base},
frontier/.style = {distance from root=3*\LD},
 level distance = \LD
        }
\Tree   [.~
            [.Adj
                [.alt R ]
                [.a AF  ] 
            ]
            [.\node[yshift=-\LD] {s}; AF ] 
        ]
    \end{tikzpicture}
\end{document}

enter image description here

5
  • Ooh, I've never used forest. But this looks neat. What does tier=L2 do here?
    – Ernesto
    Commented Feb 24, 2022 at 0:41
  • @Ernesto, with tier marked nodes it vertical align them regardless in which levels of tree they are, In this particular case are aligned nodes a\\R which is at tree bottom level (llevel 2) with s\\N which is written in the middle level. (level 1). The top level is level 0.
    – Zarko
    Commented Feb 24, 2022 at 1:20
  • @Ernesto, see edited answer (a bit improved design of trees). BTW, did any of suggested solution fulfil your expectations? Or you still wait on tikz-qtree solution?
    – Zarko
    Commented Feb 24, 2022 at 2:45
  • thanks for your explanation! Unfortunately, forest didn't work for me. As a standalone file, I replicated the tree. In my beamer file, I was able to see the text but not the edges of the tree. I believe it may have some conflict with a different package or something. I did, however, find a solution through tikz-qtree, which I added below.
    – Ernesto
    Commented Feb 27, 2022 at 1:36
  • @Ernesto, my code examples works in bemaer presentations too. Tested. See edited last example in answer, which now use beamer document class.
    – Zarko
    Commented Feb 27, 2022 at 7:04
0

After fiddling with the code, I discovered that the code I had been using works; I simply had to move the tikzset{} portion from the preamble to inside the tikzpicture environment. I don't know why having these settings in the environment works but not when they're in the preamble, but it did. Below is my "new" code and the output. I've added this solution in case it's helpful to others.

\documentclass{standalone}

\usepackage{tikz}
\usepackage{tikz-qtree}

\begin{document}
    
    \begin{tikzpicture}
        
        \tikzset{every tree node/.style={align=center,anchor=base},
            frontier/.style={distance from root=80pt}}
        
        \Tree
        [.Adj
            [.Adj
                {alt\\ R}
                {a\\ AF}
            ]
            {s\\ AF}
        ]
        
    \end{tikzpicture}
    
\end{document}

enter image description here

1
  • Your claims are false. Your code also works if \tizset is before tikzpicture or even in document preamble. The cause of your problems is somewhere else, Where, is hard to say, since your document structure and preamble is unknown to us. I suspect that in preamble (or in document) you have many of them, where the last one overwrite the previous ones.
    – Zarko
    Commented Feb 27, 2022 at 7:24

You must log in to answer this question.

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