von esdd » Sa 17. Jun 2017, 02:23
Zunächst: tikzpicture Umgebungen sollte man nicht verschachteln. Das ist auch überhaupt nicht nötig, da \matrix ebenfalls ein Node ist und sowohl einen Namen als auch ein Label erhalten und positioniert werden können.
\documentclass{scrartcl}
%encoding and language
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
%diagrams and graphics
\usepackage[svgnames]{xcolor}
\usepackage{tikz}% lädt auch xcolor, graphicx, ...
\usetikzlibrary{positioning, matrix, arrows}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt, auto, thick, every text node part/.style={align=center}]
\tikzset{
cyk/.style = {
matrix of math nodes,
row sep=-\pgflinewidth,column sep=-\pgflinewidth,
nodes={draw,minimum size=2em,font=\strut},
nodes in empty cells
}
}
\matrix[cyk, name=M1, label=above:$s_1$]
{
|[fill=Green]| & |[fill=White]|& |[fill=White]| & |[fill=Green]| \\
|[fill=White]| & |[fill=Red]| & |[fill=Green]| \\
|[fill=Green]| & |[fill=Green]| \\
|[fill=Green]| \\
};
\matrix[cyk, name=M2, right=of M1, label=above:$s_2$]
{
|[fill=Green]| & |[fill=White]| & |[fill=Green]| & |[fill=Green]| \\
|[fill=White]| & |[fill=Red]| & |[fill=Green]| \\
|[fill=Green]| & |[fill=Green]| \\
|[fill=Green]| \\
};
\path (M1) edge (M2);
\end{tikzpicture}
\end{document}
Wenn Du \matrix in einen Befehl packst, dann kannst Du dort nicht & als Spaltentrenner verwenden, sondern musst einen Ersatz definieren. Außerdem musst Du sicher stellen, dass Deine Farben auch noch außerhalb der \foreach definiert sind.
\documentclass{scrartcl}
%encoding and language
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
%diagrams and graphics
\usepackage[svgnames]{xcolor}
\usepackage{tikz}% lädt auch xcolor, graphicx, ...
\usetikzlibrary{positioning, matrix, arrows}
\tikzset{
cyk/.style = {
matrix of math nodes,
row sep=-\pgflinewidth,column sep=-\pgflinewidth,
nodes={draw,minimum size=2em,font=\strut},
nodes in empty cells
}
}
\newcommand{\cykstate}[2][]{%
\foreach[count=\i] \j in {#2}
{%
\ifcase \j
\xglobal\colorlet{cellcolor\i}{Red}%
\or
\xglobal\colorlet{cellcolor\i}{Green}%
\or
\xglobal\colorlet{cellcolor\i}{White}%
\fi
}%
\matrix[cyk, ampersand replacement=\&, #1]
{
|[fill=cellcolor1]| \& |[fill=cellcolor2]| \& |[fill=cellcolor3]| \& |[fill=cellcolor4]| \\
|[fill=cellcolor5]| \& |[fill=cellcolor6]| \& |[fill=cellcolor7]| \\
|[fill=cellcolor8]| \& |[fill=cellcolor9]| \\
|[fill=cellcolor10]| \\
};%
}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt, auto, thick, every text node part/.style={align=center}]
\cykstate[name=M1, label=above:$s_1$]{1,2,2,1,2,0,1,1,1,1}
\cykstate[name=M2, right=of M1, label=above:$s_2$]{1,2,1,1,2,0,1,1,1,1}
\cykstate[name=M3, right=of M2, label=above:$s_3$]{1,1,1,1,2,0,1,1,1,1}
\path
(M1) edge (M2)
(M2) edge (M3)
;
\end{tikzpicture}
\end{document}
Ergebnis:
Edit: Im ersten Beispiel arrows Bibliothek ergänzt.
- Dateianhänge
-
- gl_farbwahl.png (6.68 KiB) 1274 mal betrachtet
Zunächst: [tt]tikzpicture[/tt] Umgebungen sollte man nicht verschachteln. Das ist auch überhaupt nicht nötig, da [tt]\matrix[/tt] ebenfalls ein Node ist und sowohl einen Namen als auch ein Label erhalten und positioniert werden können.
[code]\documentclass{scrartcl}
%encoding and language
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
%diagrams and graphics
\usepackage[svgnames]{xcolor}
\usepackage{tikz}% lädt auch xcolor, graphicx, ...
\usetikzlibrary{positioning, matrix, arrows}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt, auto, thick, every text node part/.style={align=center}]
\tikzset{
cyk/.style = {
matrix of math nodes,
row sep=-\pgflinewidth,column sep=-\pgflinewidth,
nodes={draw,minimum size=2em,font=\strut},
nodes in empty cells
}
}
\matrix[cyk, name=M1, label=above:$s_1$]
{
|[fill=Green]| & |[fill=White]|& |[fill=White]| & |[fill=Green]| \\
|[fill=White]| & |[fill=Red]| & |[fill=Green]| \\
|[fill=Green]| & |[fill=Green]| \\
|[fill=Green]| \\
};
\matrix[cyk, name=M2, right=of M1, label=above:$s_2$]
{
|[fill=Green]| & |[fill=White]| & |[fill=Green]| & |[fill=Green]| \\
|[fill=White]| & |[fill=Red]| & |[fill=Green]| \\
|[fill=Green]| & |[fill=Green]| \\
|[fill=Green]| \\
};
\path (M1) edge (M2);
\end{tikzpicture}
\end{document} [/code]
Wenn Du [tt]\matrix[/tt] in einen Befehl packst, dann kannst Du dort nicht [tt]&[/tt] als Spaltentrenner verwenden, sondern musst einen Ersatz definieren. Außerdem musst Du sicher stellen, dass Deine Farben auch noch außerhalb der [tt]\foreach[/tt] definiert sind.
[code]\documentclass{scrartcl}
%encoding and language
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
%diagrams and graphics
\usepackage[svgnames]{xcolor}
\usepackage{tikz}% lädt auch xcolor, graphicx, ...
\usetikzlibrary{positioning, matrix, arrows}
\tikzset{
cyk/.style = {
matrix of math nodes,
row sep=-\pgflinewidth,column sep=-\pgflinewidth,
nodes={draw,minimum size=2em,font=\strut},
nodes in empty cells
}
}
\newcommand{\cykstate}[2][]{%
\foreach[count=\i] \j in {#2}
{%
\ifcase \j
\xglobal\colorlet{cellcolor\i}{Red}%
\or
\xglobal\colorlet{cellcolor\i}{Green}%
\or
\xglobal\colorlet{cellcolor\i}{White}%
\fi
}%
\matrix[cyk, ampersand replacement=\&, #1]
{
|[fill=cellcolor1]| \& |[fill=cellcolor2]| \& |[fill=cellcolor3]| \& |[fill=cellcolor4]| \\
|[fill=cellcolor5]| \& |[fill=cellcolor6]| \& |[fill=cellcolor7]| \\
|[fill=cellcolor8]| \& |[fill=cellcolor9]| \\
|[fill=cellcolor10]| \\
};%
}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt, auto, thick, every text node part/.style={align=center}]
\cykstate[name=M1, label=above:$s_1$]{1,2,2,1,2,0,1,1,1,1}
\cykstate[name=M2, right=of M1, label=above:$s_2$]{1,2,1,1,2,0,1,1,1,1}
\cykstate[name=M3, right=of M2, label=above:$s_3$]{1,1,1,1,2,0,1,1,1,1}
\path
(M1) edge (M2)
(M2) edge (M3)
;
\end{tikzpicture}
\end{document}[/code]
Ergebnis:
[img]http://golatex.de/files/gl_farbwahl_105.png[/img]
[size=75]Edit: Im ersten Beispiel [tt]arrows[/tt] Bibliothek ergänzt.[/size]