使用 Tikz 注释表格;添加箭头

使用 Tikz 注释表格;添加箭头

我希望能够绘制一个箭头,上面有一些文字,用向左的箭头连接表格中任意两个单元格(即可能不是最右/最左,可能不相邻)。具体来说,我试图在表格顶部画一个箭头,看起来类似于你得到的箭头这里,尽管我的表格单元格中不包含数字,但我正在寻找一种不连接所有单元格而只连接成对相邻单元格的解决方案。我不确定修改它的正确方法是什么。

我正在使用beamer,并且tikz(尽管我对它还很陌生)和tabularx

有没有办法做到这一点?

编辑:这是我正在弄乱的代码。我不知道如何修复。

    \documentclass[pdf]{beamer}
    \mode<presentation>{}
    \usepackage[english]{babel}
    \usepackage{natbib}
    \usepackage{color, colortbl}
    \renewcommand{\bibnumfmt}[1]{#1.}
    \usepackage{ marvosym }
    \usepackage{ tikzsymbols }
    \usepackage{ wasysym }
    \usepackage{tikz}
    \usetikzlibrary{tikzmark, positioning, fit,shapes.misc}

    \usetikzlibrary{decorations.pathreplacing, calc}


         \newcommand{\tikzmark}[2][-3pt]{\tikz[remember picture, overlay, baseline=-0.5ex]\node[#1](#2){};}

         \tikzset{brace/.style={decorate, decoration={brace}},
         brace mirrored/.style={decorate, decoration={brace,mirror}},
        }

          \newcounter{brace}
          \setcounter{brace}{0}
          \newcommand{\drawbrace}[3][brace]{%
          \refstepcounter{brace}
         \tikz[remember picture, overlay]\draw[#1] (#2.center)--(#3.center)node[pos=0.5, name=brace-\thebrace]{};
       }

      \newcounter{arrow}
      \setcounter{arrow}{0}
      \newcommand{\drawcurvedarrow}[3][]{%
      \refstepcounter{arrow}
      \tikz[remember picture, overlay]\draw (#2.center)edge[#1]node[coordinate,pos=0.5, name=arrow-\thearrow]{}(#3.center);
       }

       \newcommand{\annote}[3][]{%
       \tikz[remember picture, overlay]\node[#1] at (#2) {#3};
       }



       \newcommand\marktopleft[1]{
        \tikz[overlay,remember picture] 
        \node (marker-#1-a) at (0,1.5ex) {};
      }
       \newcommand\markbottomright[1]{
       \tikz[overlay,remember picture] 
      \node (marker-#1-b) at (0,0) {};
      \tikz[overlay,remember picture,thick,dashed,inner sep=3pt]
      \node[draw,rounded rectangle,fit=(marker-#1-a.center) (marker-#1-b.center)] {};
      }

     \usepackage{tabularx}
     \usepackage{stmaryrd}
     \usepackage{amsmath}
    \usepackage{mathtools}
    \usepackage{xcolor}

   \makeatletter
   \newcommand{\redub}{}
    \def\redub#1{%
    \@ifnextchar_%
      {\@redub{#1}}
      {\@latex@warning{Missing argument for \string\redub}\@redub{#1}_{}}%
     }
      \def\@redub#1_#2{%
      \colorlet{currentcolor}{.}%
      \color{red}%
      \underbrace{\color{currentcolor}#1}_{\color{red}#2}%
      \color{currentcolor}%
     }

      \newcounter{savedenumi}
      \newenvironment{moreenum}{%
       \setcounter{savedenumi}{\value{enumi}}%
       \begin{enumerate}\setcounter{enumi}{\value{savedenumi}}%
    }{%
      \end{enumerate}%
     }
      \AtBeginSection[]
   {
    \begin{frame}<beamer>
        \frametitle{}
        \tableofcontents[currentsection]
     \end{frame}
    }



    \newcolumntype{g}{>{\columncolor{red}}c}


     \begin{document}
     \begin{frame}
     \begin{tabular}{ | l | l |}
        \hline
        letter & number \\ \hline
        \tikzmark[xshift=-8pt,yshift=1ex]{x}A &  1\tikzmark[xshift=3.5em]{a} \\ \hline
         A &  2 \\ \hline
        \tikzmark[xshift=-8pt,yshift=-1ex]{y}A &  1\tikzmark[xshift=3.5em]{b} \\ \hline
        \tikzmark[xshift=-8pt,yshift=1ex]{w}B &  1 \\ \hline
        \tikzmark[xshift=-8pt,yshift=-1ex]{z}B &  2 \\ \hline
    \end{tabular}
   \drawcurvedarrow[bend left=60,-stealth]{a}{b}
   \drawbrace[brace mirrored, thick]{x}{y}
   \drawbrace[brace mirrored, thick]{w}{z}
   \annote[right]{arrow-1}{Duplicate}
   \annote[left]{brace-1}{A}
   \annote[left]{brace-2}{B}


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

 \begin{table}
   \centering
    \begin{tabular}{|c|c|c|g|c|}
     \hline
    bla   &  bla  & bla   & $b_1$\tikzmark{a} \\ \hline
    bla   &  bla  & bla   & bla \\\hline   
    bla   &  bla  & bla   & bla \\\hline   
    bla   &  bla  & bla   & bla \\\hline
    bla   &  bla  & bla   & bla \\\hline   
   \end{tabular}
  \end{table}
\begin{tikzpicture}[remember picture,overlay]
\node [right=2cm,above=2cm,minimum width=0pt] at (pic cs:a) (A) {A};
\draw [<-,out=5,in=180] ([xshift=15pt]{pic cs:a}) to (A);
\end{tikzpicture}
\end{frame}

\end{document}

答案1

例如,如果您重写原始代码以使用,则可以执行以下操作tikzmark。请注意,我从您的 MWE 中删除了无关紧要的内容。

\documentclass[pdf]{beamer}
\mode<presentation>{}
\usepackage[english]{babel}
\usepackage{color, colortbl}
\usepackage{tikz}
\usetikzlibrary{tikzmark, positioning, fit, shapes.misc}

\usetikzlibrary{decorations.pathreplacing, calc}

\tikzset{brace/.style={decorate, decoration={brace}},
  brace mirrored/.style={decorate, decoration={brace,mirror}},
}

\newcolumntype{g}{>{\columncolor{red}}c}

\begin{document}
  \begin{frame}
    \begin{tabular}{ | l | l |}
      \hline
      letter & number \\ \hline
      \tikzmark{x}A &  1\tikzmark{a} \\ \hline
      A &  2 \\ \hline
      \tikzmark{y}A &  1\tikzmark{b} \\ \hline
      \tikzmark{w}B &  1 \\ \hline
      \tikzmark{z}B &  2 \\ \hline
    \end{tabular}
    \begin{tikzpicture}[remember picture, overlay]
      \draw ($(pic cs:a) + (3.5em,0)$) edge[bend left=60,-stealth] ($(pic cs:b) + (3.5em,0)$) node [midway, right, xshift=5pt, yshift=5pt] {Duplicate};
      \draw[brace mirrored, thick] ($(pic cs:x) + (-8pt,1ex)$)--($(pic cs:y) + (-8pt,-1ex)$) node [midway, left] {A};
      \draw[brace mirrored, thick] ($(pic cs:w) + (-8pt,1ex)$)--($(pic cs:z) + (-8pt,-1ex)$) node [midway, left] {B};
    \end{tikzpicture}

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

    \begin{table}
      \centering
      \begin{tabular}{|c|c|c|g|c|}
        \hline
        bla   &  bla  & bla   & $b_1$\tikzmark{c} \\ \hline
        bla   &  bla  & bla   & bla \\\hline
        bla   &  bla  & bla   & bla \\\hline
        bla   &  bla  & bla   & bla \\\hline
        bla   &  bla  & bla   & bla \\\hline
      \end{tabular}
    \end{table}
    \begin{tikzpicture}[remember picture,overlay]
      \node [right=2cm,above=2cm,minimum width=0pt] at ({pic cs:c}) (A) {A};
      \draw [<-,out=5,in=180] ([xshift=15pt]{pic cs:c}) to (A);
    \end{tikzpicture}
  \end{frame}

\end{document}

这将注释命令与绘图命令集成在一起,从而省去了以后定义注释点的麻烦。它用于calc调整定位,而不是改变原始标记的定位。这节省了一些计数器。我发现将所有内容放在一个覆盖图中比担心让一堆命令一起工作效果更好,但您的公里数显然可能会有所不同。

箭头和括号

相关内容