如何在多个表格单元格周围绘制线条

如何在多个表格单元格周围绘制线条
\documentclass[fleqn,12pt,a4paper]{article}
\usepackage{tabularx}
   \begin{document}
\begin{table}[ht]
  \begin{minipage}[b]{1 \linewidth}\centering
   \begin{tabular}{|c|c|c|c|c|}
    \hline
      Tri Sankhya & Vihbakti    & Ekavachana & Dvivachana & Bahuvachana \\
   \hline
      Pra Trik  & Prathama   & Su (s)& Au & Jas (as) \\
      Dvi Trik & Dvitiya & Am & Aut (Au) & Shas(as) \\
      Tri Trik  & Trutiya  & Ta (A) & Bhyam & Bhis \\ 
      Cha Trik  & Chaturthi  & Ne (E) & Bhyam & Bhyas \\
      Pan   Trik & Panchami  & Nasi (as)& Bhyam & Bhyas  \\
      Shas Trik & Shashthi  & Nas (as)& Os & Aam   \\
      Sap Trik & Saptami & Ni (ee) & Os & Sup(su)  \\
   \hline
     \end{tabular}
      \caption{Subanta Pratyaya}
   \end{minipage}
  \end{table}
 \end{document} 

我创建了一个如上所示的表格。但是,我试图创建一个如图片中所示的表格。我该如何实现呢?图片中的文本是梵文,但在上面的例子中,我将其改为英文。我尝试在 Tikz 中创建节点,但没有成功,我也找不到如何在选定的表格单元格上实现自由手绘轮廓。我不知道如何将文本放在表格之外,以及如何用箭头将文本连接到表格单元格的所需部分。非常感谢您的帮助。 替代文本

答案1

这是一种可能性,当然可以做一些调整,但它展示了这个概念:

\documentclass[fleqn,12pt,a4paper]{article}

\usepackage{tikz}
\usepackage{tabularx}

\begin{document}

% Introduce a new counter for counting the nodes needed for circling
\newcounter{nodecount}
% Command for making a new node and naming it according to the nodecount counter
\newcommand\tabnode[1]{\addtocounter{nodecount}{1} \tikz \node (\arabic{nodecount}) {#1};}

% Some options common to all the nodes and paths
\tikzstyle{every picture}+=[remember picture,baseline]
\tikzstyle{every node}+=[inner sep=0pt,anchor=base,
minimum width=1.8cm,align=center,text depth=.25ex,outer sep=1.5pt]
\tikzstyle{every path}+=[thick, rounded corners]

\begin{table}[ht]
  \begin{minipage}[b]{1 \linewidth}\centering
   \begin{tabular}{|c|c|c|c|c|}
    \hline
      Tri Sankhya & Vihbakti    & Ekavachana & Dvivachana & Bahuvachana \\
   \hline
% Turn the cells needed for defining the circling paths into nodes with our custom command
      Pra Trik  &Prathama  & \tabnode{Su (s)} & \tabnode{Au} & \tabnode{Jas (as)} \\
      Dvi Trik & Dvitiya & \tabnode{Am} & \tabnode{Aut (Au)} & \tabnode{Shas(as)} \\
      Tri Trik  & Trutiya  & \tabnode{Ta (A)} & \tabnode{Bhyam} & Bhis \\ 
      Cha Trik  & Chaturthi  & Ne (E) & Bhyam & Bhyas \\
      Pan   Trik & Panchami  & Nasi (as)& Bhyam & Bhyas  \\
      Shas Trik & Shashthi  & Nas (as)& Os & Aam   \\
      Sap Trik & Saptami & \tabnode{Ni (ee)} & Os & \tabnode{Sup(su)}  \\
   \hline
     \end{tabular}
      \caption{Subanta Pratyaya}
   \end{minipage}


\begin{tikzpicture}[overlay]
% Define the circle paths
\draw [blue](1.north west) -- (3.north east) --
(3.south east) -- (3.south west) -- (5.south east) -- (4.south west) -- cycle;
\draw [red] (6.north west) -- (6.north east) --
(10.south east) -- (9.south west) -- (7.north west) -- (8.north east) -- cycle;
\draw [orange] (2.north west) -- (2.north east) -- (5.south east) --
(5.south west) -- cycle;

% Labels
\node [right=2cm,above=2cm,minimum width=0pt] at (2) (A) {A};
\draw [<-,out=5,in=180] (2) to (A);
\node [right=2.2cm,above=1cm,minimum width=0pt] at (3) (B) {B};
\draw [<-,out=0,in=180] (3) to (B);
\node [right=1.2cm,below=1cm,minimum width=0pt] at (10) (C) {C};
\draw [<-,out=350,in=90] (10) to (C);

\end{tikzpicture}

\end{table}
\end{document} 

带有单元格组(用圆圈圈出并标注)的表格

答案2

一种解决方案是创建一个表格,{NiceTabular}其中nicematrix单元格下有 TikZ 节点,并使用 TikZ 绘制线条。

TikZ 说明是 Jake 的回答中的说明。

\documentclass[fleqn,12pt,a4paper]{article}
\usepackage{nicematrix,tikz}

\begin{document}

\tikzset
  {
    every path/.append style = { thick, rounded corners } , 
    every node/.append style = 
      { 
        inner sep=0pt,
        anchor=base,
        minimum width=1.8cm,
        align=center,
        text depth=.25ex,
        outer sep=1.5pt
      }
  }

\begin{table}[ht]
\centering
   \begin{NiceTabular}{ccccc}[vlines,create-medium-nodes]
    \hline
      Tri Sankhya & Vihbakti    & Ekavachana & Dvivachana & Bahuvachana \\
    \hline
      Pra Trik  &Prathama  & Su (s) & Au & Jas (as) \\
      Dvi Trik & Dvitiya & Am & Aut (Au) & Shas(as) \\
      Tri Trik  & Trutiya  & Ta (A) & Bhyam & Bhis \\ 
      Cha Trik  & Chaturthi  & Ne (E) & Bhyam & Bhyas \\
      Pan   Trik & Panchami  & Nasi (as)& Bhyam & Bhyas  \\
      Shas Trik & Shashthi  & Nas (as)& Os & Aam   \\
      Sap Trik & Saptami & Ni (ee) & Os & Sup(su)  \\
    \hline
    \CodeAfter
    \begin{tikzpicture} [name suffix = -medium]
    % Define the circle paths
    \draw [blue] (2-3.north west) -- (2-5.north east) -- (2-5.south east) 
                 -- (2-5.south west) -- (3-4.south east) -- (3-3.south west) -- cycle ;
    \draw [red] (3-5.north west) -- (3-5.north east) -- (8-5.south east) 
                -- (8-3.south west) -- (4-3.north west) -- (4-4.north east) -- cycle ;
    \draw [orange] (2-4.north west) -- (2-4.north east) -- (3-4.south east) 
                    -- (3-4.south west) -- cycle;

    % Labels
    \node [right=2cm,above=2cm,minimum width=0pt] at (2-4) (A) {A};
    \draw [<-,out=5,in=180] (2-4) to (A);
    \node [right=2.2cm,above=1cm,minimum width=0pt] at (2-5) (B) {B};
    \draw [<-,out=0,in=180] (2-5) to (B);
    \node [right=1.2cm,below=1cm,minimum width=0pt] at (8-5) (C) {C};
    \draw [<-,out=350,in=90] (8-5) to (C);
    \end{tikzpicture}
   \end{NiceTabular}
\caption{Subanta Pratyaya}
\end{table}
\end{document} 

上述代码的输出

相关内容