1

I have a problem with some packages interfering (I think). I am working on a document where I both want to have a tikz diagram and a table with some of the cells colored. For the cell color, I use the xcolor package, which gave an error that I tried solving with what was said here: Option clash for package xcolor.

As is, the code works, but I want to use the commented out 'biasedstate' box, instead of simply typing 'biasedbox' as is done now (so where I define the tikzpicture, I want to replace 'biasedbox' with \usebox{\biasedstate}). However, simply uncommenting the code for the biasedstate box gives an error and I don't understand why.

I know that it has to do with the xcolor package because when I remove ',table' from the first line and remove \cellcolor{red!25}, the biasedstate box works fine.

\documentclass[11pt,A4paper,table]{article}%
\usepackage{tikz-cd}
\usetikzlibrary{positioning}
\usepackage{tabularx}

\newsavebox{\fairstate} \newsavebox{\biasedstate}

\sbox{\fairstate}{ \begin{tabular}{|l r|} \multicolumn{2}{c}{\textbf{Fair}} \tabularnewline \hline 1: & 1/6\ 2: & 1/6\ 3: & 1/6\ 4: & 1/6\ 5: & 1/6\ 6: & 1/6\ \hline \end{tabular} } %\sbox{\biasedstate}{ % \begin{tabular}{|l r|} % \multicolumn{2}{c}{\textbf{Biased}} \tabularnewline % \hline % 1: & 1/10\ % 2: & 1/10\ % 3: & 1/10\ % 4: & 1/10\ % 5: & 1/10\ % 6: & 1/2\ % \hline % \end{tabular} %}

\begin{document} \begin{tikzpicture}[>=stealth,->,shorten >=1pt,looseness=1,auto] \matrix [matrix of nodes] { \node (fair) [shape=rectangle] {\usebox{\fairstate}}; \node (biased) [shape=rectangle,right=of fair] {biasedbox};\ }; \draw (fair) to [bend left] node [pos=0.55] {0.05} (biased); \draw (biased) to [bend left] node [pos=0.45] {$0.1$} (fair); \path[every node/.style={auto=false},every loop/.style={looseness=5}] (fair) edge [loop left] node [midway] {0.95} () (biased) edge [loop right] node [midway] {0.9} (); \end{tikzpicture}

\begin{tabularx}{300pt}{ccc} a&b&c\ d&e&\cellcolor{red!25}f \end{tabularx}

\end{document}

enter image description here

Anton V.
  • 111

0 Answers0