[Tex/LaTex] Centering trees

horizontal alignmentlinguexlinguisticstikz-treestrees

How can I centre a tree, moving it to the middle of the page, whilst keeping \ex. in its normal position?

\documentclass[12pt,a4paper]{article}   
\usepackage{tikz-qtree}
\usepackage{tikz-qtree-compat}
\usepackage{linguex}

\begin{document}

\ex. \begin{tikzpicture}
     \Tree [.VP [.V saw ] [.DP [.N Kim ] ] ]
     \end{tikzpicture}

\end{document}

Best Answer

The basic problem here has more to do with how to center a linguex example than how to center the tree, so it is actually asking essentially the same thing as gb4e center example text, but for linguex instead of gb4e. The solutions end up being the same:

  • Use \hfil before and after the tikzpicture environment, as suggested by Harish Kumar's comment on the question linked above.
  • Use \hspace*{\fill} before and after the tikzpicture environment, as suggested by egreg's comment to this answer.
  • Use \hfill before and after the tikzpicture environment, as suggested by Peter Grill's answer to the question linked above. You just have to make sure there is something with zero width at the end of the example (I used \hspace{0pt} below, but you could use \null as Peter Grill did); otherwise, the tree will be right-aligned instead of centered.

These yield the following output:

enter image description here

\documentclass[12pt,a4paper]{article}   
\usepackage{tikz-qtree}
\usepackage{tikz-qtree-compat}
\usepackage{linguex}
\usepackage{showframe} % this just shows where the margins are -- comment out for the final version
\usepackage{lipsum} % for dummy text

\begin{document}

\ex. \lipsum[121]

\ex. \hfil
     \begin{tikzpicture}[baseline] % baseline makes the example number stay at the top of the tree
     \Tree [.VP [.V saw ] [.DP [.N Kim ] ] ]
     \end{tikzpicture}%
     \hfil

\ex. \hspace*{\fill}
     \begin{tikzpicture}[baseline] % baseline makes the example number stay at the top of the tree
     \Tree [.VP [.V saw ] [.DP [.N Kim ] ] ]
     \end{tikzpicture}%
     \hspace*{\fill}

\ex. \hfill
     \begin{tikzpicture}[baseline] % baseline makes the example number stay at the top of the tree
     \Tree [.VP [.V saw ] [.DP [.N Kim ] ] ]
     \end{tikzpicture}%
     \hfill\hspace{0pt} % without \hspace{0pt}, the tree would be right-aligned

\ex. \lipsum[130]

\end{document}
Related Question