9

I'm planning to use the following numbered examples in a document (see example below). I would like the number to be at the top of the example, but for the ones with diagrams it ends up in the middle. Is there an easy way to fix this?

\documentclass[]{article}
\usepackage{tikz-qtree-compat}
\usepackage{tikz}
\usepackage{stmaryrd}
\usepackage{gb4e}

\begin{document}

\begin{exe}
\ex{Ann dances.}
\end{exe}

\begin{exe}
\ex
\begin{tikzpicture}[baseline=(current  bounding  box.center)]
\Tree [.S_0 [.NP [Bill ] ] [.VP [.V said ] [.NP \node(a){that}; ] ] ]
\begin{scope}[shift={(2in,0in)}] 
\Tree [.\node(b){S_1}; [.NP Ann ] [.VP dances ] ]
\end{scope}
\draw[->](\subtreeof{a}.0) .. controls +(west:0) and +(west:1) .. (b);
\end{tikzpicture}
\end{exe}


\begin{exe}
\ex
$\left\llbracket
\begin{array}{l}
\Tree [ .S [.NP [.N Ann ] ] [.VP [.V dances ] ] ]
\end{array}
\right\rrbracket$
\end{exe}

\end{document}
3
  • 1
    See this question: tex.stackexchange.com/questions/5023/… Nov 15, 2010 at 18:40
  • 1
    That post answers the question for the case where I'm using tikzpciture. Thanks. Is there a way to do the same thing for the array?
    – twsh
    Nov 15, 2010 at 19:23
  • Oh. These things are arrays, not a list? Sorry, I am not familiar with the packages you are using. But from the generated output, it looks very list like to me, so I suspect that using some form of list would be more appropriate. Nov 15, 2010 at 20:10

1 Answer 1

7

Well, if you can imagine typesetting anything, it can almost certainly be done in TeX. However, finding an elegant solution to this problem took a little work. So I'm hoping that this is the ouput you wanted to see:

alt text

Here's the code that produced that list (it adds 5 lines to your code, marked by the arrows):

\documentclass{article}
\usepackage{tikz-qtree-compat}
\usepackage{tikz}
\usepackage{stmaryrd}
\usepackage{gb4e}

\usepackage{booktabs}                    % <----

\begin{document}

\begin{exe}
\ex{Ann dances.}
\end{exe}

\begin{exe}
\ex
\begin{tabular}[t]{l}\toprule[-12pt]     % <----
  \begin{tikzpicture}[baseline=(current  bounding  box.center)]
  \Tree [.S_0 [.NP [Bill ] ] [.VP [.V said ] [.NP \node(a){that}; ] ] ]
  \begin{scope}[shift={(2in,0in)}] 
  \Tree [.\node(b){S_1}; [.NP Ann ] [.VP dances ] ]
  \end{scope}
  \draw[->](\subtreeof{a}.0) .. controls +(west:0) and +(west:1) .. (b);
  \end{tikzpicture}
\\ \end{tabular}                         % <----
\end{exe}

\begin{exe}
\ex
\begin{tabular}[t]{l}\toprule[-12pt]     % <----
  $\left\llbracket
  \begin{array}{l}
  \Tree [ .S [.NP [.N Ann ] ] [.VP [.V dances ] ] ]
  \end{array}
  \right\rrbracket$
\\ \end{tabular}                         % <----
\end{exe}

\end{document}

Explanation:

Because exe is a gb4e-redefined list, and \ex is a gb4e-redefined \item, the first part of the job involved dropping each of your objects (tikzpicture and math-set array) into a \begin{tabular}[t]{l} environment, the [t] instructing tabular to set its baseline at the top.

All well and good, except that you need to issue an \hline somewhere in the environment to prod tabular into doing its work. That turns out to be problematic for two reasons: first, you probably don't want to see an ugly line across the top of your objects, and second, the \ex item number is now vertically aligned with the middle of the \hline, effectively quite some way above the top of each object. Not smooth.

Enter the booktabs package. It provides several \hline replacements (including \toprule, which we use). However, most wonderfully, you can can pass it an argument specifying the thickness of the line. So, \toprule[0pt] effectively eliminates the visual line. Even more wonderfully, you can pass it a negative number which acts like a negative \vspace, except without the problem that \vspace's can't be added here.

Voila. All that's left to do is to fine-tune \toprule's negative thickness to your exact requirements. Oh, and maybe add a little indentation to the "Ann dances" \ex to align it with your other objects (\ex{\quad Ann dances.} should do it). : )

4
  • 1
    @Tom, credit where credit is due: Harald's solution at tex.stackexchange.com/questions/5023/… works perfectly well for the \ex $...$ and Matthew's works perfectly well for the tikzpicture. Taken together, they produce identical output to mine. Nov 16, 2010 at 15:26
  • Thank-you! I'm not sure I see what you mean about the answer you link to though. All the examples there require tikzpicture, don't they? My (3) doesn't. I acknowledged that it works for (2), which does use tikzpicture.
    – twsh
    Nov 17, 2010 at 4:44
  • @Tom (@Harald): no, as intimated in my comment above, Harald's solution works for any \item, whether TikZ object, $...$ or whatnot. His example being a tikzpicture might have thrown you off. Undernearth the covers, \ex is esentially a glorified item (read gb4e.sty to see). So, practically regardless of the object type, Harald's \ex \leavevmode\vadjust{\vspace{-\baselineskip}}\newline should also work (nb, substituting your use of \ex for his use of \item). I.e., Harald's reference in his comment to his earlier solution was all you really needed. Try it for your (3), you'll see. Nov 17, 2010 at 11:45
  • I see now, that's good to know.
    – twsh
    Nov 17, 2010 at 17:32

You must log in to answer this question.

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