Usually, LaTeX adds \ignorespaces
at the begin of a cell and \unskip
at its end to automatically remove spaces at the begin and end of the cell contents.
The example loads package collcell
, but does not use it. An example of its usage:
\documentclass{article}
\usepackage{minted}
\usepackage{collcell}
\newcommand{\ccode}[1]{\mintinline{C}{#1}}
\begin{document}
\begin{tabular}{| >{\collectcell{\ccode}}l<{\endcollectcell} | l |}
\hline
int foo (int a, int b) & Foos a and b. \\ \hline
int bar (int* a, int* b) & Bars a and b. \\ \hline
\end{tabular}
\end{document}

PS: I had to use C
(uppercase) as language name to get the proper output.
Analysis of the problem in the MWE of the question
First the MWE of the question with some modifications:
- Uppercase
C
as language name,
- Package
collcell
is not needed, but it loads package array
, which implements <
and >
for the columns specification of the table.
Modified MWE:
\documentclass{article}
\usepackage{array}
\usepackage{minted}
\newcommand{\ccode}[1]{\mintinline{C}{#1}}
\begin{document}
\begin{tabular}{| >{\ccode}l | l |}
\hline
int foo (int a, int b) & Foos a and b. \\ \hline
int bar (int* a, int* b) & Bars a and b. \\ \hline
\end{tabular}
\end{document}

\ccode
is inserted in front of the cell contents. LaTeX automatically surrounds the cell contents with \ignorespaces
and \unskip
to remove spaces at the begin and end of a cell. Then the first cell becomes:
\ccode \ignorespaces int foo (int a, int b)\unskip
Since curly argument braces are missing, the argument of \ccode
is the first token \ignorespaces
. The remaining part int foo (int a, int )\unskip
is set as plain text.
\unskip
could be used as end token for the argument and \ignorespaces
can be absorbed by adding it to the parameter text of the definition of \ccode
:
\def\ccode\ignorespaces#1\unskip{\mintinline{C}{#1}}
Full example:
\documentclass{article}
\usepackage{array}
\usepackage{minted}
\def\ccode\ignorespaces#1\unskip{\mintinline{C}{#1}}
\begin{document}
\begin{tabular}{| >{\ccode}l | l |}
\hline
int foo (int a, int b) & Foos a and b. \\ \hline
int bar (int* a, int* b) & Bars a and b.\\ \hline
\end{tabular}
\end{document}
Package cellcoll
hides these internals, providing a more readable and maintainable interface.