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}
  • 3
    Your MWE doesn't compile without adding \usepackage{linguex}. The same was true of the question you asked yesterday. Please edit the question to fix this, and try to make sure the MWE compiles as it is before submitting the question. – Jason Zentz Aug 6 '15 at 12:43
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}
  • 1
    Use \hspace*{\fill} instead. – egreg Aug 6 '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 6 '15 at 16:19

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.