1

I have this macro \code that produces a box. And I want to create a tabular "environment" that acts like enumerate except it puts the items into a grid.

\documentclass{article}

\usepackage{tabularx}
\usepackage{multirow}

\def\code#1{\hbox{\vtop{\tt\def\\{\egroup\hbox\bgroup}\hbox\bgroup#1\egroup}}}

\def\twocolenum#1{{
  \newcounter{cnt}
  \setcounter{cnt}{0}
  \newbox{\cell}
  \newcolumntype{I}{>{\bgroup\setbox\cell=\hbox\bgroup}l<{\egroup\ifdim\wd\cell=0pt\else\stepcounter{cnt}\hskip1em\llap{(\alph{cnt})}\hskip1ex\usebox{\cell}\the\ht\cell\fi\egroup}}
  \begin{tabular}{II}
    #1
  \end{tabular}
}}

\begin{document}
\twocolenum{
  \multirow{2}{*}{\code{x = 0; \\ while (x >= 0) \{ \\ \ \ \ \ x++; \\ \}}} & bIt \\
      & cIt \\
  dIt & eIt \\
}
\end{document}

what I expected was a grid of (a) (b) \\ (c) \\ (d) (e). That works, except for some reason the cell that contains \code appears to have height 0pt and thus the code overlaps with the empty cell and the d cell. I know that all I am doing is hackish but can I somehow fix the behaviour to avoid the overlap?

  • Why don't you make a complete example instead of posting all this snippets? – Ulrike Fischer Sep 23 '15 at 9:11
  • With \newcounter and \newbox in the definition of \twocolenum you're looking for disgrace. What do you need a new box register for? – egreg Sep 23 '15 at 9:14
  • I know, this is just first attempt, but I am currently facing a completely different problem. the box is for saving the contents of the cell and analyzing them before shipping them out. – user88326 Sep 23 '15 at 9:16
  • \multirow sets the dimension of its content to 0pt (so that it doesn't push the rows apart). – Ulrike Fischer Sep 23 '15 at 9:32
  • Yes, any way to overcome that and make it still make sense? – user88326 Sep 23 '15 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy