Is it possible to use the pipe character, |, to separate cells in a table?

If you are not using | for anything else

\catcode`\|=4 

Instead of (inherently fragile) catcode trickery, as suggested by David, you could also define a simple helper macro with delimited arguments:

\documentclass{scrartcl}
\usepackage{array}
\begin{document}

  \def\row#1|#2|#3\\{#1 & #2 & #3 \tabularnewline}
  \begin{tabular}{ccc}
    \row c1 | c2 | c3 \\
    \row c4 | c5 | c6 \\
  \end{tabular}
\end{document}

Even though the extra \row at the beginning of each row is a bit more to type, it also brings you some extra flexibility: You now can easily rearrange, skip, or format columns, by just changing the definition of \row: For instance, \def\row#1|#2|#3\\{\textbf{#1} & & #3 \tabularnewline} would typset the first column in boldface and (maybe temporarily) skip the second column.


Here's a ConTeXt solution using the database module. The idea is to define a separated list with a vertical bar as separator and table macros as delimiters. Example:

\usemodule [database]

\defineseparatedlist
  [Table]
  [separator=|,
   before=\bTABLE, after=\eTABLE,
   first=\bTR, last=\eTR,
   left=\bTD, right=\eTD]

\starttext
  \startTable
    alpha | beta   | gamma
    first | second | third
  \stopTable
\stoptext

result

As separators the strings comma (default), tab, or space can be used or just any character like I did with the vertical bar here.

The same technique can be used to typeset CSV data as well since the macros, separators and the quoting can be configured.

Tags:

Tables