我想绘制附加的表格。搜索了整个网站,尝试使用 strickthrough 绘制表格中的线条,并尝试使用 tikzmark 绘制箭头。
这是我的 MWE:
% !TeX spellcheck = en_GB
\documentclass[12pt ,hidelinks]{article}
\usepackage{pgfplots}
\usepackage{amssymb}
\usepackage{parskip}% this stops indent of first line in paragraph
%\usepackage[fleqn]{amsmath}
%\setlength{\mathindent}{0pt}
\usepackage{amsmath} % need for align environment
\usepackage{xcolor}
\usepackage{mathpazo} %and mathptmx package for extra large fonts
\usepackage{graphicx}
\usepackage[margin=0.5in]{geometry}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{% <---- BEWARE
\node[shape=circle, red,draw,inner sep=1pt] (char) {#1};}}
\usetikzlibrary{calc}
\usepackage{colortbl}% this colour cells
\begin{document}
\huge{Question 1}
\vspace{2cm}
\renewcommand{\arraystretch}{1.5}
\begin{table}[!ht]
\centering
\resizebox{\linewidth}{!}{%
\begin{tabular}{|c||c|c|c|c|c|c|c|}
\cline{2-8}
\multicolumn{1}{c||}{}
& A & B & C & D & E &F&G\\ \hline \hline
A & - & & 310& -&300& &620 \\ \hline
B & - & - &550& 430&530 &\circled{330}&-\\ \hline
C & \circled{310} & 550 & - &-&350&-&-\\ \hline
D & &430& - &-&-&210&390\\ \hline
E& \circled{300} &530&350&-&- &380&360\\ \hline
F&-&330&-&210& \circled{380} &-&2.8 \\ \hline
G&620&-&-&390& \circled{360}&-&-\\ \hline
\end{tabular}}
\end{table}
\end{document}
这使:
答案1
对于这样的事情蒂克兹 matrix of nodes
是理想的。请参阅手册第 59.1 节了解详细信息。
使用matrix of nodes
你可以生成:
使用代码:
\documentclass[svgnames]{article}
\usepackage{tikz}
\usetikzlibrary{matrix, arrows.meta}
\tikzset{
Cells/.style={every node/.append style={#1},},
border/.style={fill=SlateGray,text=white},
main/.style={fill=DarkKhaki!20,
rectangle,
text height=1.4ex,
text width=3ex,
text depth = 0.4ex,
align=center,
anchor=base
},
}
\begin{document}
\begin{tikzpicture}
\matrix (M)[matrix of nodes,
Cells=main,
row sep=0.8mm,column sep=0.8mm,
row 1/.style={Cells=border},
column 1/.style={Cells=border},
]{
& A & B & C & D & E & F & G \\
A & - & - &310& - &300& - &620\\
B & - & - &550&430&530&330& - \\
C &310&550& - & - &350& - & - \\
D & - &420& - & - & - &210&390\\
E &300&530& - & - & - &380&360\\
F & - &330& - &210&380& - & - \\
G &620& - & - &390&360& - & - \\
};
\foreach \x in {2,...,8} {
\draw[{Latex[]}-, thick, SlateGray]([yshift=0.5]M-1-\x.north)--++(0,0.5);
}
\draw[Tomato] (M-2-1.west)--(M-2-8.east);
\foreach \c [count=\r from 3] in {7,2,7,2,6,6}{
\draw[Tomato] (M-\r-1.west)--(M-\r-\c.west);
\draw[Tomato] (M-\r-\c) ellipse [x radius=2.4ex,y radius=1.8ex];
\draw[Tomato] (M-\r-\c.east)--(M-\r-8.east);
}
\end{tikzpicture}
\end{document}
我还没有把颜色弄对。样式有点特别,但很容易调整。
后面(M)
说矩阵的行和列\matrix
中的单元格可以称为。当然,你可以用任何东西代替。如上所述,节点坐标等非常有用。r
c
(M-r-c)
M
(M-r-c.north)