5 关于diagbox宏包画表格线的一个问题

发布于 2022-05-19 19:56:56

diagbox宏包定义了几种表格线样式,能满足基本需求。但是对于复杂的表格斜线就有些难以实现了,能否定义一个更自由的画线命令,通过平移左上角和右下角的坐标实现画线自由?
503d269759ee3d6d7133bc6941166d224e4ade9e.png

查看更多

关注者
0
被浏览
240
1 个回答
雾月
雾月 2022-05-19

你可以用 nicematrix,它能够使用 tikz 绘制复杂表格(不能跨页)。

image.png

\documentclass{ctexart}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{nicematrix}
\usetikzlibrary{intersections,patterns,decorations.pathmorphing}

\begin{document}

\begin{NiceTabular}{>{\centering}p{2cm}p{2cm}p{2cm}c}[hvlines,
  create-large-nodes,left-margin,right-margin]
\Block{2-3}{~} & & & 什么?\\
~ &~ &~ & \Block{1-1}{wh\\at?} \\
1 & 2 & 3 & 4
\CodeAfter
  \begin{tikzpicture}
  \draw[pattern=north west lines] ([xshift=-1em,yshift=1em]3-4-large.north west) rectangle ([xshift=1pt,yshift=-.5pt]3-4-large.south east);
  \path[fill=red!30] ([xshift=1em-1pt]1-1-large.north west) arc (0:-90:1em) --([xshift=-1pt]1-1-large.north west) --cycle;
  \draw (1-1-large.north west)-- node[midway,below left=-2pt]{看看} (2-2-large.south west);
  \draw[decorate,decoration={snake}] (1-1-large.north west)-- node[pos=0.6,below left=-2.5pt]{第二} (2-3-large.south west);
  \draw (1-1-large.north west)-- node[near end,below left]{上下} (1-4-large.south west);
  \path[name path=a] (1-1-large.north west)--(2-4-large.south west);
  \draw[name path=b] (3-3-large.north west)--(1-4-large.south west);
  \draw[name intersections={of=a and b, name=itr}] (itr-1)-- node[pos=.4,above right=-2pt]{what} (3-4-large.north west);
  \draw[dashed] (1-1-large.north west)--(itr-1);
  \draw (itr-1)--(3-1-large.north west);
  \end{tikzpicture}
\end{NiceTabular}

\end{document}

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览