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.


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


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:


  • 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 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.