# How can I get TikZ to work within a \tabularx environment?

I'm putting together a poster for a conference using beamer. In one column, the poster has some text next to which I want to put a neuron diagram-style figure next to some text. Pictures embed in this with without a problem. But when I include my TikZ code it doesn't work. The preamble includes:

    \begin{block}{BlockTitle}

\begin{columns}
\begin{column}{.80\textwidth}
\begin{itemize}
\item[] TEXT
\end{itemize}

\end{column}
\begin{column}{.20\textwidth}

\centering
\begin{tabularx}{\linewidth}{r}

{\begin{tikzpicture}
\matrix[mymx, amperstand replacement=\&] (mx) {
\& C_1 \\
|[plain]|  \&\& |[selroute]|E_1 \\
\& C_2  \\
|[plain]| \&\& |[plain]|\phantom{E} \\
\& C_3 \\
};
{[route]

\foreach \y in {1,3,5} {
\draw (mx-\y-2) -- (mx-2-3);

}

\end{tikzpicture}}
\\
\includegraphics[width=.80\linewidth]{PICTURE.jpg}
\\

\end{tabularx}
\end{column}
\end{columns}
\vskip-1ex

\end{block}


The preamble includes:

  \usepackage{tikz}
\usetikzlibrary{scopes,matrix,positioning}
\tikzset{
mymx/.style={matrix of math nodes,nodes=myball,column sep=4em,row sep=-1ex},
myball/.style={draw,circle,inner sep=0pt},
mylabel/.style={midway,sloped,fill=white,inner sep=1pt,outer sep=1pt,below,
execute at begin node={$\scriptstyle},execute at end node={$}},
plain/.style={draw=none,fill=none},
sel/.append style={fill=green!10},
prevsel/.append style={fill=red!10},
route/.style={-latex,thick},
selroute/.style={route,blue!50!green}
}


Does anybody have any suggestions?

-
TikZ code per se in a tabularx environment works. Can you post a complete working (or non-working) document (with \documentclass{} and \begin{document}...\end{document}) instead of code fragments You only need to add as much code as will show the problem (i.e. not your entire preamble, probably). –  Alan Munn Jun 23 '12 at 19:34
Also, if the code you posted is copied from your document, you've misspelt 'ampersand' in your matrix options. Maybe this is your problem? –  Alan Munn Jun 23 '12 at 19:43

Your example is not exactly best of its kind. Please next time compile yourself to make sure that it is indeed something that others can also compile and work on.

First of all you don't need to tabularize the pictures since it's only a slide and you can always tweak the column to match what you are going for.

Also, you have empty cells without nodes but you are supplying them node options which are not needed unless you add nodes in empty cells option.

You open your block and put two columns in it. When you take the \end{block} to its correct place you get one less error.

\documentclass[12pt]{beamer}
\usepackage{tabularx,tikz}
\usetikzlibrary{scopes,matrix,positioning}
\tikzset{
mymx/.style={matrix of math nodes,nodes=myball,column sep=4em,row sep=-1ex},
myball/.style={draw,circle,inner sep=0pt},
mylabel/.style={midway,sloped,fill=white,inner sep=1pt,outer sep=1pt,below,
execute at begin node={$\scriptstyle},execute at end node={$}},
plain/.style={draw=none,fill=none},
sel/.append style={fill=green!10},
prevsel/.append style={fill=red!10},
route/.style={-latex,thick},
selroute/.style={route,blue!50!green}
}

\begin{document}
\begin{frame}
\begin{columns}[c]
\begin{column}{0.5\textwidth}
\begin{block}{BlockTitle}
\begin{itemize}
\item Text
\end{itemize}
\end{block}
\end{column}
\begin{column}{.5\textwidth}
\centering
\begin{tabularx}{\linewidth}{r}
{\begin{tikzpicture}
\matrix[mymx,nodes in empty cells, ampersand replacement=\&] (mx) {
\& C_1 \& \\
|[plain]|\&     \& |[selroute]|E_1 \\
\& C_2 \& \\
|[plain]|\&     \& |[plain]| \phantom{E}\\
\& C_3 \& \\
};
{[route]
\foreach \y in {1,3,5} {
\draw (mx-\y-2) -- (mx-2-3);
}
}
\end{tikzpicture}
}\\
\includegraphics[width=.80\linewidth]{dsotm.jpg}
\end{tabularx}
\end{column}
\end{columns}
\end{frame}
\end{document}


-
Thanks you so much Percusse! Your suggestions helped me to simplify the code and get to the point where the TikZ images are at least rendered in the document. However, as this is for a poster (not a slide) my problem now is finding a way to scale the TikZ images to .80\linewidth, just as I can with the .jpgs... –  Aktrop Jun 24 '12 at 6:29
\scalebox{<factor>} did the trick! –  Aktrop Jun 24 '12 at 6:40
@Aktrop Use beamerposter package to ease the pain. –  percusse Jun 24 '12 at 10:44