# Minted inside tabular

I know this question has been asked before, but it didn't quite solve my issue. (How to embed a minted environment inside a tabular environment?)

The described workaround (bringing \end{minted} to a single line) does work, however only if the code comes second. When I try to put the minted-section into the first column I get this error:

! LaTeX Error: Something's wrong--perhaps a missing \item.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \begin{Verbatim}[commandchars=\\\{\}, ]


I used this code:

\begin{tabular}{rp{0.5\textwidth}}
\begin{minted}{c}
int main() {
printf("hello, world");
return 0;
}
\end{minted}
& testing
\end{tabular}


What can I do? Thank you

• The first column is an r type one, so paragraphs are not allowed in it. – egreg Jul 3 '14 at 17:39
• Welcome to the site! Stating @egreg's solution explicitly, try \begin{tabular}{p{0.5\textwidth}r}. Let us know if this resolves the issue :) Welcome! – cmhughes Jul 3 '14 at 17:52

If you look at the linked question, you'll see that the minted environment appears in the second column, which is declared as p type.

You can't have an enumerated list or a center environment or anything that requires breaking lines in a column declared as r.

So just declare the first column as p. For instance

\begin{tabular}{p{0.5\textwidth} r}
\begin{minted}{c}
int main() {
printf("hello, world");
return 0;
}
\end{minted}
& testing
\end{tabular}


will work.

Of course the alignment will be wrong. You can remedy by adding a minipage:

\documentclass{article}
\usepackage{minted}
\begin{document}
\begin{tabular}{p{0.5\textwidth} r}
\begin{minipage}[t]{0.5\textwidth}
\begin{minted}{c}
int main() {
printf("hello, world");
return 0;
}
\end{minted}
\end{minipage}
& testing
\end{tabular}
\end{document}