如何创建带有空白字段且无线条的表格

如何创建带有空白字段且无线条的表格

我甚至不知道如何正确地问这个问题,我想要这个在此处输入图片描述

但我只能这样做在此处输入图片描述

我的代码是

\documentclass[a4paper,12p]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[table]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, automata, backgrounds, positioning, fit,petri}
\usepackage{xcolor}
\colorlet{hallo}{black!75}

\setlength\parindent{0pt}

\title{Hausaufgabe 21, Automatenminimierung}
\date{\today}

\begin{document}
    
    \maketitle
    
    \section{}
    
    Konstruieren Sie mit Hilfe des Minimierungsverfahren für deterministische endliche Automaten einen äquivalenten minimalen DFA $ M' $. Geben Sie dazu die in diesem Verfahren erstellte Tabelle an. \\\\
    
    \begin{tabular}{c|c|c|c|c|c|c|c|c|c}
        & $ z_{0} $ & $ z_{1} $ & $ z_{2} $ & $ z_{3} $ & $ z_{4} $ & $ z_{5} $ & $ z_{6} $ & $ z_{7} $ & $ z_{8} $ \\
        \hline
        $ z_{0} $ & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} \\
        \hline
        $ z_{1} $ & $ \times $ & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} \\
        \hline
        $ z_{2} $ & $ \times $ & {\color{blue} $ \times $} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} \\
        \hline
        $ z_{3} $ & $ \times $ & {\color{blue} $ \times $} & {\color{blue} $ \times $} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} \\
        \hline
        $ z_{4} $ & & $ \times $ & $ \times $ & $\times$ & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} \\
        \hline
        $ z_{5} $ & $ \times $ & & {\color{blue} $ \times $} & {\color{blue} $ \times $} & $ \times $ & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} \\
        \hline
        $ z_{6} $ & $ \times $ & {\color{blue} $ \times $} & & {\color{blue} $ \times $} & $ \times $ & {\color{blue} $ \times $ }& \cellcolor{hallo} & \cellcolor{hallo} & \cellcolor{hallo} \\
        \hline
        $ z_{7} $ & $ \times $ & {\color{blue} $ \times $} & & {\color{blue} $ \times $} & $ \times $ & {\color{blue} $ \times $} & & \cellcolor{hallo} & \cellcolor{hallo} \\
        \hline
        $ z_{8} $ & & $ \times $ & $ \times $ & $ \times $ & & $ \times $ & $ \times $ & $ \times $ & \cellcolor{hallo}
    \end{tabular}
    
\end{document}

答案1

这是一个不使用 TikZ 的解决方案。

在此处输入图片描述

关于此代码与您的代码有何不同,有一些评论:

  1. 我使用array而不是tabular,这样就省去了输入令牌的几十次麻烦$。没有那么多$字符确实有助于大大简化输入。
  2. 使用\cline{2-2}\cline{2-3}、 等来\cline{2-9}代替\hline
  3. 在最后一行,借助\multicolumn{1}{c}{...}包装器抑制垂直线。
  4. {\color{blue} $ \times $}将所有的 实例替换为,这样可以节省一些输入笔画\bluetimes,我们\newcommand\bluetimes{\textcolor{blue}{\times}}在序言中设置了 。

\documentclass[a4paper,12pt]{scrartcl}
\usepackage{array} % for '\extrarowheight' macro
\usepackage[ngerman]{babel}
%%\usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\newcommand\bluetimes{\textcolor{blue}{\times}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\setlength\parindent{0pt}

\begin{document}
\hrule % illustrate width of textblock
\[ % initiate unnumbered displaymath group
\setlength\extrarowheight{2pt} % optional -- for a more open "look"
\begin{array}{ *{9}{c|}}
   \cline{2-2}
   z_1 & \times \\
   \cline{2-3}
   z_2 & \times & \bluetimes \\
   \cline{2-4}
   z_3 & \times & \bluetimes & \bluetimes \\
   \cline{2-5}
   z_4 & & \times & \times & \times \\
   \cline{2-6}
   z_5 & \times & & \bluetimes & \bluetimes & \times \\
   \cline{2-7}
   z_6 & \times & \bluetimes & & \bluetimes & \times & \bluetimes \\
   \cline{2-8}
   z_7 & \times & \bluetimes & & \bluetimes & \times & \bluetimes & \\
   \cline{2-9}
   z_8 & & \times & \times & \times & & \times & \times & \times \\
   \cline{2-9}
   \mc{} & \mc{z_0} & \mc{z_1} & \mc{z_2} & \mc{z_3} & \mc{z_4} & \mc{z_5} & \mc{z_6} & \mc{z_7}  
\end{array}
\]
    
\end{document}

答案2

这是一个{NiceTabular}使用 的解决方案nicematrix

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}[first-col,last-row,hvlines,corners]{cccccc}
$z_1$ & \NotEmpty \\
$z_2$ & \NotEmpty & \NotEmpty \\
$z_3$ & x & x & x \\
$z_4$ & x & x & x & \NotEmpty \\
$z_5$ & x & x & x & x & x \\
$z_6$ & x & x & x & x & x & \NotEmpty \\
      & $z_0$ & $z_1$ & $z_2$ & $z_3$ & $z_4$ & $z_5$ \\
\end{NiceTabular}

\end{document}

我们需要几次编译(因为nicematrix在后台使用 PGF/Tikz 节点)。

上述代码的输出

答案3

如果你定义

\def\li #1 {\edef\liF{\liF\hbox to1.5em{\hss$#1$\hss}}\kern-.4pt\hbox\bgroup\hbox to2em{\hss$#1$\hss}\kern.5em \liA}
\def\liA #1{\ifx;#1\egroup \else \liB{#1}\expandafter\liA\fi}
\def\liB #1{\kern-.4pt\lower.3em\vbox{\hrule\hbox to1.5em{\vrule height.9em depth.3em\liC{#1}\vrule}\hrule}} 
\def\liC #1{\hss$\ifx#1.\else\ifx#1y\color{blue}\fi\times\fi$\hss}
\def\liF {\kern1ex\noindent\kern2.5em}

那么您可以更简单地创建这样的“表格”:

\vbox{\offinterlineskip
   \li z_1  x;
   \li z_2  xy;
   \li z_3  xyy;
   \li z_4  .xxx;
   \li z_5  x.yxx;
   \li z_6  xy.yxy;
   \li z_7  xy.yxy.;
   \li z_8  .xxx.xxx;
   \liF
}

答案4

tabularray

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}
\[
\begin{tblr}{colspec={cccccc},
    rows = {3.5mm}, 
    columns = {3.5mm},
    vline{2,3}={1-Y}{solid},
    vline{4}={2-Y}{solid},
    vline{5}={3-Y}{solid},
    vline{6}={4-Y}{solid},
    vline{7}={5-Y}{solid},
    vline{8}={6-Y}{solid},
    vline{9}={7-Y}{solid},
    vline{10}={8-Y}{solid},
    hline{1}={2}{solid},
    hline{2}={2-3}{solid},
    hline{3}={2-4}{solid},
    hline{4}={2-5}{solid},
    hline{5}={2-6}{solid},
    hline{6}={2-7}{solid},
    hline{7}={2-8}{solid},
    hline{8}={2-9}{solid},
    hline{9}={2-10}{solid},
    cell{2,3}{3,4} = {fg=blue},
    cell{5-7}{3-5} = {fg=blue},
    cell{6-7}{7} = {fg=blue},
    }
z_1 & \times \\
z_2 & \times & \times \\
z_3 & \times & \times & \times \\
z_4 &  & \times & \times & \times \\
z_5 & \times &  & \times & \times & \times \\
z_6 & \times & \times &  & \times & \times & \times  \\
z_7 & \times & \times &  & \times & \times & \times  \\
z_8 & & \times & \times & \times & & \times & \times & \times  \\
& z_0 & z_1 & z_2 & z_3 & z_4 & z_5 & z_6 & z_7\\
\end{tblr}
\]
\end{document}

在此处输入图片描述

相关内容