TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create a table for a few blocks of source code. In LaTeX, I would do


Is there a way to accomplish something like this in ConTeXt? I have tried \starttyping and \stoptyping within table cells, but the file fails to compile if I do that.

The reason I would like to use tables is that I could then use \placetable for floats, and also that I would have a clean way of referring to it in other parts of the document.

share|improve this question
up vote 5 down vote accepted

Use buffers. Store the content in a buffer using


and retrieve it using \typebuffer. Here is a simple example with tables.

\startsetups table:setup
  \setupTABLE[row][last][bottomframe=on, framethickness=3bp]

#include <iostream.h>

void main()
  cout << "Hello World\n";

puts "Hello World"

  \NC C++                \NC Ruby              \NC \NR
  \NC \typebuffer[CPP]   \NC \typebuffer[ruby]  \NC \NR

which gives

enter image description here

share|improve this answer
This suits my document well. Thanks! – prash Feb 15 '12 at 17:51

The first thing: Verbatin text in tables work:


    \NC Foo        \NC Bar \NC\AR
    \NC \type{Foo} \NC Bar \NC\AR

        \bTD Foo \eTD
        \bTD Bar \eTD
        \bTD Foo        \eTD
        \bTD \type{Bar} \eTD


Result: firstresult

The second thing is that you don't need a table to refer to your code. You can create your own floating type. However even that doesn't have to float. The following code creates a custom floating evironment, not perfect, but hopefully enough to get you started.

\definefloat [code] [codes]


\input knuth

As illustrated in \in{code}[code:example].

\startplacecode [title=Some example code., reference=code:example]
        int main(){
            return 0;


It looks like this:


share|improve this answer
Your first answer works only with single line text, so I can't use it. I like your second answer, and will use it later. For the moment, though, I need tables. – prash Feb 15 '12 at 17:55
If you need more text, then buffers is the way to go, see Adityas anwser. – Marco Feb 15 '12 at 18:08

Your Answer


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.