9

I try to enclose my syntax tree in a growing double bracket using \left \llbracket ... \right \rrbracket. However, the tree always sits in the lower half and leaving the upper half blank, which is very ugly... What's more, I cannot make the angle bracket grow with the tree...

\documentclass{article}
\usepackage{stmaryrd}
\usepackage{qtree}
\usepackage{tikz-qtree}
\begin{document}

$\left \llbracket \textbf{\Tree [.S [.S [ [.NP [.N Ann ] ] [.VP [.V smokes ] ] ] ] and [.S [ [.NP [.N John ] ] [.VP [.V drinks ] ] ] ] ]} \right \rrbracket$ \\
$\left \langle \left ( \Tree [.S [.NP [.N Ann ] ] [.VP [.V smokes ] ] ] \right ) \right \rangle$

\end{document}

enter image description here

7

Use the baseline option to set the baseline at the same height as the center of the picture (minus half the x height).

Code

\documentclass{article}
\usepackage{stmaryrd}
\usepackage{tikz-qtree}
\begin{document}
\[ \left \llbracket
  \tikz[font=\bfseries, baseline={([yshift=+-.5ex]current bounding box.center)}]{
    \Tree [.S [.S [ [.NP [.N Ann ] ] [.VP [.V smokes ] ] ] ] and
          [.S [ [.NP [.N John ] ] [.VP [.V drinks ] ] ] ] ]
  } \right \rrbracket\]

\[ \left\langle \left(
   \tikz[baseline={([yshift=+-.5ex]current bounding box.center)}]{
     \Tree [.S [.NP [.N Ann ] ] [.VP [.V smokes ] ] ]}
   \right) \right\rangle \]
\end{document}

Output

enter image description here

  • If the trees are on the same line, they will no longer be aligned by the baselines of the original trees i.e. the baseline of the root node, as seems usual in linguistics. – cfr Jun 6 '17 at 1:46
5

You can also either use the gathered environment of amsmath or a more low-level \vcenter{\hbox{}} construction: (but no clue for your \rangle's)

\documentclass{article}
\usepackage{stmaryrd}
%\usepackage{qtree}
\usepackage{tikz-qtree}
\usepackage{amsmath}
% \usepackage{forest}
\begin{document}

% here a construction with gathered and package forest for the tree
% $\left \llbracket
%   \begin{gathered}
%     \textbf{\begin{forest}
%       [S [S [ [NP [N [Ann] ] ] [VP [V [smokes] ] ] ] ] [and] [S [[NP [N [John]
%       ]] [VP [V [drinks] ] ]] ] ]
%     \end{forest}}
% \end{gathered}
% \right \rrbracket$ \\

$\left \llbracket \vcenter{%
      \hbox{\bfseries\Tree [.S [.S [ [.NP [.N Ann ] ] [.VP [.V smokes ] ] ] ] and [.S [ [.NP [.N John ] ] [.VP [.V drinks ] ] ] ] ]}} \right \rrbracket$ 


% with gathered:

$\left \langle \left (
    \begin{gathered}
      \Tree [.S [.NP [.N Ann ] ] [.VP [.V smokes ] ] ]
    \end{gathered}
\right ) \right \rangle$

% with \vcenter and \hbox:

$\left \langle \left (
    \vcenter{%
      \hbox{\Tree [.S [.NP [.N Ann ] ] [.VP [.V smokes ] ] ]}%
    }
\right ) \right \rangle$

\end{document}

centeredtrees


If you want to have multiple trees on same line:

\documentclass{article}
\usepackage{stmaryrd}
\usepackage{tikz-qtree}
\usepackage{amsmath}

\newbox\mytreebox
\newbox\mytreeboxwithdelim

\makeatletter
\newcommand\TreeWithDelim [3]{%
   \setbox\mytreebox\hbox{{#3}}%
   \setbox\mytreeboxwithdelim\hbox{$#1\vcenter{\copy\mytreebox}#2$}%
   \dimen@=\dimexpr\ht\mytreeboxwithdelim+\dp\mytreeboxwithdelim\relax
   % in my testing, same as total height of non decorated treebox
   \leavevmode\raise\dimexpr-.5\dimen@-\fontdimen22\textfont2+\ht\mytreebox\relax\box\mytreeboxwithdelim
}
\makeatother


\begin{document}

\noindent\rlap{\rule{\linewidth}{0.4pt}}%
XX\TreeWithDelim {\left\llbracket}{\right\rrbracket}
    {\bfseries\Tree [.S [.S [ [.NP [.N Ann ] ] [.VP [.V smokes ] ] ] ] and [.S [ [.NP [.N John ] ] [.VP [.V drinks ] ] ] ] ]}\hfill
\TreeWithDelim {\left\langle\left(}{\right)\right\rangle}
    {\Tree [.S [.NP [.N Ann ] ] [.VP [.V smokes ] ] ]}XX

\end{document}

enter image description here

The horizontal rule is for demonstrative purposes only.

  • If the trees are on the same line, they will no longer be aligned by the baselines of the original trees i.e. the baseline of the root node, as seems usual in linguistics. – cfr Jun 6 '17 at 1:47
  • @cfr updated... – user4686 Jun 6 '17 at 8:00
2

This combines Forest with the new coffins to create a tree style

delimit tree={<left delimiter>}{<right delimiter>}

It tries to keep the baselines correct, although I am not certain that I've got this quite right, so it may need tweaking. (It worked with minimal testing, but I don't really trust it.)

Given the definition of the new style, this allows us to write

\begin{forest}
  for tree={
    font=\bfseries,
  },
  delimit tree={\left\llbracket}{\right\rrbracket}
  [S
    [S
      [
        [NP
          [N
            [Ann]
          ]
        ]
        [VP
          [V
            [smokes]
          ]
        ]
      ]
    ]
    [and]
    [S
      [
        [NP
          [N
            [John]
          ]
        ]
        [VP
          [V
            [drinks]
          ]
        ]
      ]
    ]
  ]
\end{forest}
\begin{forest}
  delimit tree={\left\langle\left(}{\right)\right\rangle}
  [S
    [NP
      [N
        [Ann]
      ]
    ]
    [VP
      [V
        [smokes]
      ]
    ]
  ]
\end{forest}

Note that this maintains (I think!) the corrected alignment of the trees on the baseline.

aligned trees

Complete code:

\documentclass[border=10pt]{standalone}
\usepackage{stmaryrd,xcoffins}
\usepackage[linguistics]{forest}
\NewCoffin\OuterForestCoffin
\NewCoffin\InnerForestCoffin
\forestset{%
  delimit tree/.code n args=2{%
    \forestset{%
      draw tree stage/.style={
        for root'={
          draw tree box=0,
          draw tree,
          TeX={%
            \SetHorizontalCoffin\InnerForestCoffin{\box0}%
            \SetHorizontalCoffin\OuterForestCoffin{%
              $#1 \TypesetCoffin\InnerForestCoffin[vc,l]#2$%
            }%
            \TypesetCoffin\OuterForestCoffin[t,l](0pt,(\CoffinTotalHeight{\OuterForestCoffin}-\CoffinTotalHeight{\InnerForestCoffin})+\CoffinHeight{\InnerForestCoffin})%
          },
        },
      },
    }%
  },
}
\begin{document}
\begin{forest}
  for tree={
    font=\bfseries,
  },
  delimit tree={\left\llbracket}{\right\rrbracket}
  [S
    [S
      [
        [NP
          [N
            [Ann]
          ]
        ]
        [VP
          [V
            [smokes]
          ]
        ]
      ]
    ]
    [and]
    [S
      [
        [NP
          [N
            [John]
          ]
        ]
        [VP
          [V
            [drinks]
          ]
        ]
      ]
    ]
  ]
\end{forest}
\begin{forest}
  delimit tree={\left\langle\left(}{\right)\right\rangle}
  [S
    [NP
      [N
        [Ann]
      ]
    ]
    [VP
      [V
        [smokes]
      ]
    ]
  ]
\end{forest}
\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.