3

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}
Jason Zentz
  • 4,158
user65526
  • 845

1 Answers1

5

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}
Jason Zentz
  • 4,158
  • 1
    Use \hspace*{\fill} instead. – egreg Aug 06 '15 at 15:39
  • \hspace*{\fill} adds a zero skip at the end just to avoid the problem you saw with \hfill, which is due to the fact that \par always issues \unskip. – egreg Aug 06 '15 at 16:19