Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

For a list of things to be used inside the formula enviroment, I want to create boxes stacked over each other. I basically want to write

$$ A := "Box with lines like 'A is a number', 'A is bigger than 3',... " $$

What I come up with is is

\newcommand{\mybox}[2]{\stackrel{\fbox{$#1$}}{\fbox{$#2$}}} 

but it pretty much sucks when it comes to what I really want. It's only two boxes and they don't even touch each other. Their length depends on the content. It should look more like a shelf. The length of all boxes should fit (the height might depend on the content). Also, the box should be oriented such that the := is in the vertical center. But if I want to use my construction for more than two boxes I have to do stupid things like

\mybox{statement 1}{\mybox{and statement 2}{statement 3}}

enter image description here

share|improve this question

1 Answer 1

up vote 8 down vote accepted

What about a simple tabular?

\documentclass{article}
\usepackage{colonequals}

\begin{document}

\begin{equation}
  A \colonequals
  \begin{tabular}{|c|}
    \hline
    statement 1\\\hline
    and statement 2\\\hline
    statement 3\\\hline
  \end{tabular}
\end{equation}

\end{document}

Result:

Boxes via tabular

Edit: Making a n-ary function:

\documentclass{article}
\usepackage{colonequals}

\usepackage{kvsetkeys}

\makeatletter
\newcommand*{\boxes}[1]{%
  \begingroup
    \toks@={%
      \begin{tabular}{|c|}%
      \hline
    }%
    \comma@parse{#1}\box@entry
    \the\toks@
    \end{tabular}%
  \endgroup
}
\newcommand*{\box@entry}[1]{%
  \toks@=\expandafter{\the\toks@
    #1\tabularnewline
    \hline
  }%
}
\makeatother

\begin{document}

\begin{equation}
  A \colonequals
  \boxes{
    statement 1,
    and statement 2,
    {statement 3, 4 and 5},% comma needs to be protected by braces
    another statement,
  }
\end{equation}

\end{document}

Result:

Boxes with n-ary function

The contents of the tabular is first written in a token register. That avoids trouble with cell groups and empty lines at the end.

Edit: Further reading:

share|improve this answer
    
Looks good, do you see a possibility of making it an n-ary function? –  NikolajK Aug 16 '12 at 20:37
    
Cool, could you please elaborate a bit on that. It seems tha \comma@parse command takes the argument apart by its comma seperations and on each you somehow apply \box@entry by saving it with \toks@ as running variable. But What is \the and how does the recursion work? –  NikolajK Aug 17 '12 at 12:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.