创建自定义表格

创建自定义表格

我想要生成下表:

期望输出

我想在乳胶中复制:

  1. 除标签 AE 和 OD 周围的水平线和垂直线外,没有边框

  2. 行和列之间要留出一定的距离,以免条目看起来太拥挤

  3. 一个红色箭头指向表格上的一些数字

我已经得到如下结果:

我得到了什么

这是通过下面附加的代码获得的:

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{fancyheadings}
\usepackage{bigints}
\usepackage{color}
\usepackage{tcolorbox}
\usepackage{stackengine,graphicx,xcolor}
\usepackage{booktabs,array}
\usepackage{hyperref}
\usepackage{lscape}
\usetikzlibrary{arrows,automata}
\usepackage[thinlines]{easytable}
\usepackage[latin1]{inputenc}
\usetikzlibrary{arrows}
\usetikzlibrary{trees}
\usepgfplotslibrary{fillbetween}
\begin{document}
\setlength{\parindent}{0cm}
%\pagecolor{blue!13}
\fancyhf{}
\fancyhead[C]{\thepage}
\voffset = 0.1cm
\pagestyle{fancy}
\definecolor{Elite}{RGB}{37,97,172}
\definecolor{web}{RGB}{56, 102, 166}
\setlength{\parindent}{0mm}
\setcounter{page}{1}
$\begin{array}{c|ccccc}
\midrule
O & A & B & C & D & E\\
\midrule
O & \fbox{1} & 5 & X & X & X\\
A & \fbox{1} & 5 & \fbox{4} & 10 & X\\
C & \fbox{1} & \fbox{5} & \fbox{4} & 8 & X\\
B & \fbox{1} & \fbox{5} & \fbox{4} & \fbox{8} & 11\\
D & \fbox{1} & \fbox{5} & \fbox{4} & \fbox{8} & \fbox{10}\\
\end{array}$
%
\end{document}

Latex 专家,您能否建议一些修改意见以便我实现我在这种情况下想要的结果?

提前感谢您的帮助。

答案1

像这样:

在此处输入图片描述

我用过蒂克兹 matrix of nodes带有一些花哨的装饰。

方框内的条目使用

boxed/.style args={#1/#2}{row #1 column #2/.style={nodes={rectangle, draw}}}

.list与用于设置要装箱的坐标的处理程序相结合,该处理程序仅仅是以逗号分隔的row/column对的列表。

我把红色箭头抛入了一个\foreach循环。

当然,您可以根据需要添加任意样式。我已经演示了如何用蓝色编写第一行的条目。

完整代码如下:

\documentclass[border=5mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.markings,decorations.text,calc}
\begin{document}

  \tikzset{
     boxed/.style args={#1/#2}{row #1 column #2/.style={nodes={rectangle, draw}}},
     ->-/.style={decoration={markings, mark=at position 0.5 with {\arrow{stealth}}},
              postaction={decorate}}
  }

  \begin{tikzpicture}[every node/.style={minimum width=1.6em},
      boxed/.list={2/2,3/2,4/2,5/2,6/2,4/3,5/3,6/3,3/4,4/4,5/4,6/4,5/5,6/5,6/6},
    ]
    \matrix (M)[matrix of math nodes, column sep=1mm, row sep=1mm,
                row 1/.style={nodes={text=blue}}
    ]{
          O & A & B & C & D & E\\
          O & 1 & 5 & X & X & X\\
          A & 1 & 5 & 4 & 10 & X\\
          C & 1 & 5 & 4 & 8 & X\\
          B & 1 & 5 & 4 & 8 & 11\\
          D & 1 & 5 & 4 & 8 & 10\\
     };
     \draw[thin](M-1-1.north west)--(M-1-6.north east);
     \draw[thin]($ (M-2-1.north west)+(0,0.1) $)--($ (M-2-6.north east)+(0,0.1) $);
     \draw[thin](M-1-1.north east)--(M-6-1.south east);
     \foreach \x/\y [remember=\x as \xx (initially 6),
                     remember=\y as \yy (initially 6)]
                 in {6/5,4/5,4/4,3/4,3/2,2/2} {
       \draw[red,->-](M-\xx-\yy.center)--(M-\x-\y.center);
     }
  \end{tikzpicture}

\end{document}

答案2

所以我绝对不是专家——但我会用图表\tikz而不是图片来做这个。我相信知道自己在做什么的人可以自动放置节点,而不是手动放置!显然,你可以尝试如何绘制线条、是否填充节点等等。

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzstyle{boxed} = [draw,rectangle,thick,minimum height=2em,minimum width=2em]
\tikzstyle{unboxed} = [minimum height=2em,minimum width=2em]
\tikzstyle{arrowline} = [thick,color=red,->]
\begin{document}
\begin{tikzpicture}\bfseries
  \node at (0,0) {D};
  \node at (0,1) {B};
  \node at (0,2) {C};
  \node at (0,3) {A};
  \node at (0,4) {O};
  \node[boxed] at (1,0) {1};
  \node[boxed] at (2,0) {5};
  \node[boxed] at (3,0) {4};
  \node[boxed,fill=red!50](B) at (4,0) {8};
  \node[boxed,fill=red!50](A) at (5,0) {10};
  \node[boxed] at (1,1) {1};
  \node[boxed] at (2,1) {5};
  \node[boxed] at (3,1) {4};
  \node[boxed,fill=red!50](C) at (4,1) {8};
  \node at (5,1) {11};
  \node[boxed] at (1,2) {1};
  \node[boxed] at (2,2) {5};
  \node[boxed,fill=red!50](D) at (3,2) {4};
  \node[unboxed,fill=red!50] at (4,2)(H) {8};
  \node at (5,2) {$\times$};
  \node[boxed,fill=red!50](F) at (1,3) {1};
  \node[unboxed,fill=red!50](I) at (2,3) {5};
  \node[boxed,fill=red!50](E) at (3,3) {4};
  \node at (4,3) {10};
  \node at (5,3) {$\times$};
  \node[boxed,fill=red!50](G) at (1,4) {1};
  \node at (2,4) {5};
  \node at (3,4) {$\times$};
  \node at (4,4) {$\times$};
  \node at (5,4) {$\times$};
  \node at (1,5) {A};
  \node at (2,5) {B};
  \node at (3,5) {C};
  \node at (4,5) {D};
  \node at (5,5) {E};
  \draw[color=blue](-0.5,4.6) -- (5.5,4.6);
  \draw[color=blue](0.4,5.5) -- (0.4,-0.5);
  \draw[arrowline] (A.west) -- (B.east);
  \draw[arrowline] (B.north) -- (C.south);
  \draw[arrowline] (C.north) -- (H.south);
  \draw[arrowline] (H.west) -- (D.east);
  \draw[arrowline] (D.north) -- (E.south);
  \draw[arrowline] (E.west) -- (I.east);
  \draw[arrowline] (I.west) -- (F.east);
  \draw[arrowline] (F.north) -- (G.south);

\end{tikzpicture}
\end{document}

桌子

相关内容