我怎样才能在乳胶中表示这些表格?

我怎样才能在乳胶中表示这些表格?

我尝试在 latex 中绘制这些表格。我使用 来表示一张表格。我怎样才能像图中一样排列表格?我的一张表格的代码如下:

\begin{figure*}[h]
\centering
\tabcolsep=0.5cm
\setlength{\tabcolsep}{13pt} 
\renewcommand{\arraystretch}{1.5} 
\begin{tabular}{ |c|c|c|c| } 
\hline
\cellcolor{purple!20}1 &\cellcolor{purple!20} 1 & \cellcolor{purple!20}0 \\
\hline
\cellcolor{purple!20}0& \cellcolor{blue!20}$P_0$ &\cellcolor{purple!20} 1 \\  
\hline
\cellcolor{purple!20}0&\cellcolor{purple!20} 0 &\cellcolor{purple!20} 1 \\  
\hline
\end{tabular}
\end{figure*}

在此处输入图片描述

答案1

您填写其余部分。我构建了一个由块组成的表格;列间空间被抑制,并插入轻微的备份以补偿规则。

用户级语法易于管理。

\usepackage{xparse}如果您没有运行最新的 LaTeX 内核,则可能需要添加。

当然,如果该表不是您想要重现的表,您应该更清楚您的目标。

\documentclass{article}
\usepackage{xcolor}

\ExplSyntaxOn

\NewDocumentCommand{\automatonrule}{mmm}
 {% #1 = rule number, #2 = output, #3 = list of blocks
  \group_begin:
  \renewcommand{\arraystretch}{0}\ttfamily
  \acedoong_automatonrule:nnn { #1 } { #2 } { #3 }
  \group_end:
 }

\cs_new_protected:Nn \acedoong_block:n
 {
  \int_if_odd:nTF { #1 }
   {% odd, black box
    \fcolorbox{black}{white}{\color{black}\makebox[\height]{1}}
   }
   {% even, white box
    \fcolorbox{black}{black}{\color{white}\makebox[\height]{0}}
   }
 }

\cs_new_protected:Nn \acedoong_automatonrule:nnn
 {
  \begin{tabular}{@{}c@{\hspace{-\fboxrule}}c@{\hspace{-\fboxrule}}c@{}l@{}}
  \acedoong_block:n { \tl_item:nn { #3 } { 1 } } &
  \acedoong_block:n { \tl_item:nn { #3 } { 2 } } &
  \acedoong_block:n { \tl_item:nn { #3 } { 3 } } \\[-\fboxrule]
  \acedoong_block:n { \tl_item:nn { #3 } { 4 } } &
  \acedoong_block:n { \tl_item:nn { #3 } { 5 } } &
  \acedoong_block:n { \tl_item:nn { #3 } { 6 } } &
  ${}\rightarrow{}$\acedoong_block:n { #2 }  \\[-\fboxrule]
  \acedoong_block:n { \tl_item:nn { #3 } { 7 } } &
  \acedoong_block:n { \tl_item:nn { #3 } { 8 } } &
  \acedoong_block:n { \tl_item:nn { #3 } { 9 } } &
  \enspace\normalfont\itshape rule~#1
  \end{tabular}
 }

\ExplSyntaxOff



\begin{document}

\begin{figure}[htp]
\centering

\automatonrule{1}{0}{111 111 000}\quad
\automatonrule{6}{0}{111 100 100}\quad
\automatonrule{11}{0}{000 000 000}\quad
\automatonrule{16}{0}{001 011 111}

\bigskip

\automatonrule{2}{0}{000 000 001}\quad
\automatonrule{7}{0}{111 111 101}\quad
\automatonrule{12}{0}{001 111 111}\quad
\automatonrule{17}{1}{111 101 000}

\caption{Best packet of cellular automata rules found by genetic algorithm}

\end{figure}

\end{document}

在此处输入图片描述

如果您不想要黑白,这里是修改后的代码。

\documentclass{article}
\usepackage{xcolor}

\ExplSyntaxOn

\NewDocumentCommand{\automatonrule}{mmm}
 {% #1 = rule number, #2 = output, #3 = list of blocks
  \group_begin:
  \renewcommand{\arraystretch}{0}\ttfamily
  \acedoong_automatonrule:nnn { #1 } { #2 } { #3 }
  \group_end:
 }

\cs_new_protected:Nn \acedoong_block:n
 {
  \int_if_odd:nTF { #1 }
   {% odd, black box
    \colorbox{purple!20}{\makebox[\height]{1}}
   }
   {% even, white box
    \colorbox{blue!20}{\makebox[\height]{0}}
   }
 }

\cs_new_protected:Nn \acedoong_automatonrule:nnn
 {
  \begin{tabular}{@{}c@{}c@{}c@{}l@{}}
  \acedoong_block:n { \tl_item:nn { #3 } { 1 } } &
  \acedoong_block:n { \tl_item:nn { #3 } { 2 } } &
  \acedoong_block:n { \tl_item:nn { #3 } { 3 } } \\
  \acedoong_block:n { \tl_item:nn { #3 } { 4 } } &
  \acedoong_block:n { \tl_item:nn { #3 } { 5 } } &
  \acedoong_block:n { \tl_item:nn { #3 } { 6 } } &
  ${}\rightarrow{}$\acedoong_block:n { #2 }  \\
  \acedoong_block:n { \tl_item:nn { #3 } { 7 } } &
  \acedoong_block:n { \tl_item:nn { #3 } { 8 } } &
  \acedoong_block:n { \tl_item:nn { #3 } { 9 } } &
  \enspace\normalfont\itshape rule~#1
  \end{tabular}
 }

\ExplSyntaxOff



\begin{document}

\begin{figure}[htp]
\centering

\automatonrule{1}{0}{111 111 000}\quad
\automatonrule{6}{0}{111 100 100}\quad
\automatonrule{11}{0}{000 000 000}\quad
\automatonrule{16}{0}{001 011 111}

\bigskip

\automatonrule{2}{0}{000 000 001}\quad
\automatonrule{7}{0}{111 111 101}\quad
\automatonrule{12}{0}{001 111 111}\quad
\automatonrule{17}{1}{111 101 000}

\caption{Best packet of cellular automata rules found by genetic algorithm}

\end{figure}

\end{document}

在此处输入图片描述

答案2

您可以使用如下表格

\begin{figure*}[h]
\centering
\tabcolsep=0.5cm
\setlength{\tabcolsep}{13pt} 
\renewcommand{\arraystretch}{1.5} 
\begin{tabular}{cccc}
\begin{tabular}{ |c|c|c|c| } 
\hline
\cellcolor{purple!20}1 &\cellcolor{purple!20} 1 & \cellcolor{purple!20}0 \\
\hline
\cellcolor{purple!20}0& \cellcolor{blue!20}$P_0$ &\cellcolor{purple!20} 1 \\  
\hline
\cellcolor{purple!20}0&\cellcolor{purple!20} 0 &\cellcolor{purple!20} 1 \\  
\hline
\end{tabular}
&
\begin{tabular}{ |c|c|c|c| } 
\hline
\cellcolor{purple!20}1 &\cellcolor{purple!20} 1 & \cellcolor{purple!20}0 \\
\hline
\cellcolor{purple!20}0& \cellcolor{blue!20}$P_0$ &\cellcolor{purple!20} 1 \\  
\hline
\cellcolor{purple!20}0&\cellcolor{purple!20} 0 &\cellcolor{purple!20} 1 \\  
\hline
\end{tabular}
\\
\begin{tabular}{ |c|c|c|c| } 
\hline
\cellcolor{purple!20}1 &\cellcolor{purple!20} 1 & \cellcolor{purple!20}0 \\
\hline
\cellcolor{purple!20}0& \cellcolor{blue!20}$P_0$ &\cellcolor{purple!20} 1 \\  
\hline
\cellcolor{purple!20}0&\cellcolor{purple!20} 0 &\cellcolor{purple!20} 1 \\  
\hline
\end{tabular}
&
\begin{tabular}{ |c|c|c|c| } 
\hline
\cellcolor{purple!20}1 &\cellcolor{purple!20} 1 & \cellcolor{purple!20}0 \\
\hline
\cellcolor{purple!20}0& \cellcolor{blue!20}$P_0$ &\cellcolor{purple!20} 1 \\  
\hline
\cellcolor{purple!20}0&\cellcolor{purple!20} 0 &\cellcolor{purple!20} 1 \\  
\hline
\end{tabular}
\end{tabular}
\end{figure*}

这只是 2x2 表格,但可以扩展。但是,如果您想更好地控制表格的放置,我会考虑在 tikz 中执行此操作:

\begin{figure}
    \centering
    \begin{tikzpicture}
        % Define colours
        \tikzstyle{my purple} = [fill=purple!20]
        \tikzstyle{my blue} = [fill=blue!20]
        % Plot one grid
        \draw[my purple] (0, 0) rectangle (1, 1) node[pos=.5] {0};
        \draw[my purple] (1, 0) rectangle (2, 1) node[pos=.5] {0};
        \draw[my purple] (2, 0) rectangle (3, 1) node[pos=.5] {1};
        \draw[my purple] (0, 1) rectangle (1, 2) node[pos=.5] {0};
        \draw[my blue] (1, 1) rectangle (2, 2) node[pos=.5] {\(P_0\)};
        \draw[my purple] (2, 1) rectangle (3, 2) node[pos=.5] {1};
        \draw[my purple] (0, 2) rectangle (1, 3) node[pos=.5] {0};
        \draw[my purple] (1, 2) rectangle (2, 3) node[pos=.5] {0};
        \draw[my purple] (2, 2) rectangle (3, 3) node[pos=.5] {1};
        \draw (0, 0) grid (3, 3);
        % Use same grid but move around using a scope and xshift/yshift
        \begin{scope}[xshift=4cm]
            \draw[my purple] (0, 0) rectangle (1, 1) node[pos=.5] {0};
            \draw[my purple] (1, 0) rectangle (2, 1) node[pos=.5] {0};
            \draw[my purple] (2, 0) rectangle (3, 1) node[pos=.5] {1};
            \draw[my purple] (0, 1) rectangle (1, 2) node[pos=.5] {0};
            \draw[my blue] (1, 1) rectangle (2, 2) node[pos=.5] {\(P_0\)};
            \draw[my purple] (2, 1) rectangle (3, 2) node[pos=.5] {1};
            \draw[my purple] (0, 2) rectangle (1, 3) node[pos=.5] {0};
            \draw[my purple] (1, 2) rectangle (2, 3) node[pos=.5] {0};
            \draw[my purple] (2, 2) rectangle (3, 3) node[pos=.5] {1};
            \draw (0, 0) grid (3, 3);
        \end{scope}
        \begin{scope}[yshift=4cm]
            \draw[my purple] (0, 0) rectangle (1, 1) node[pos=.5] {0};
            \draw[my purple] (1, 0) rectangle (2, 1) node[pos=.5] {0};
            \draw[my purple] (2, 0) rectangle (3, 1) node[pos=.5] {1};
            \draw[my purple] (0, 1) rectangle (1, 2) node[pos=.5] {0};
            \draw[my blue] (1, 1) rectangle (2, 2) node[pos=.5] {\(P_0\)};
            \draw[my purple] (2, 1) rectangle (3, 2) node[pos=.5] {1};
            \draw[my purple] (0, 2) rectangle (1, 3) node[pos=.5] {0};
            \draw[my purple] (1, 2) rectangle (2, 3) node[pos=.5] {0};
            \draw[my purple] (2, 2) rectangle (3, 3) node[pos=.5] {1};
            \draw (0, 0) grid (3, 3);
        \end{scope}
        \begin{scope}[xshift=4cm, yshift=4cm]
            \tikzstyle{my purple} = [fill=purple!20]
            \tikzstyle{my blue} = [fill=blue!20]
            \draw[my purple] (0, 0) rectangle (1, 1) node[pos=.5] {0};
            \draw[my purple] (1, 0) rectangle (2, 1) node[pos=.5] {0};
            \draw[my purple] (2, 0) rectangle (3, 1) node[pos=.5] {1};
            \draw[my purple] (0, 1) rectangle (1, 2) node[pos=.5] {0};
            \draw[my blue] (1, 1) rectangle (2, 2) node[pos=.5] {\(P_0\)};
            \draw[my purple] (2, 1) rectangle (3, 2) node[pos=.5] {1};
            \draw[my purple] (0, 2) rectangle (1, 3) node[pos=.5] {0};
            \draw[my purple] (1, 2) rectangle (2, 3) node[pos=.5] {0};
            \draw[my purple] (2, 2) rectangle (3, 3) node[pos=.5] {1};
            \draw (0, 0) grid (3, 3);
        \end{scope}
    \end{tikzpicture}
\end{figure}

别忘了加上\usepackage{tikz}序言。 Tikz 版本的表格

相关内容