注释表格

注释表格

我正在尝试通过突出显示和注释最后一列来注释表格,但是一旦我将\tabnode和 一起使用,就会出现错位。要么是标记为 的单元格的内容\tabnode错位在表格之外,要么是单元格的宽度被拉伸(而所有单元格的宽度都应该相等)。修复此问题的正确方法是什么?这是我使用的示例代码:

   \documentclass{beamer}
   \usepackage[beamer,customcolors]{hf-tikz}
   \usepackage{tabularx}
   \begin{document}

    \begin{frame}{Title}
    \newcounter{nodecount}
    \newcommand\tabnode[1]{\addtocounter{nodecount}{1}\tikz\node(\arabic{nodecount}){#1};}

     \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]


   \newcolumntype{g}{>{\columncolor{red}}c}
   \begin{table}[ht]
     \centering
     \begin{tabular}{|c|c|c|g|}\hline
      bla   &  bla  & bla   & \tabnode{$b_1$}& \hline
  bla   &  bla  & bla   & bla            & \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}[overlay]

    \node [right=2cm,above=2cm,minimum width=0pt] at (1) (A) {A};
    \draw [<-,out=5,in=180] (1) to (A);

   \end{tikzpicture}

   \end{frame}

答案1

您的代码有一些错误,会产生错误(特别是,您声明了四列,但使用了五列,并且您忘记了换行命令):下面我纠正了它们并修复了其他方面:

\documentclass{beamer}
\usepackage[beamer,customcolors]{hf-tikz}
\usepackage{tabularx}
\usepackage{colortbl}

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

\newcommand\tabnode[1]{%
  \addtocounter{nodecount}{1}%
  \tikz[remember picture,overlay]\node[inner sep=0pt] (\thenodecount) {#1};}

\begin{document}

\begin{frame}{Title}

\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   & \tabnode{$b_1$} \\ \hline
  bla   &  bla  & bla   & bla \\\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 (1) (A) {A};
  \draw [<-,out=5,in=180] (1) to (A);
\end{tikzpicture}
\end{frame}

\end{document}

在此处输入图片描述

不过,我想向您推荐另一种使用该tikzmark库的方法:总体思路仍然相同;使用 \tikzmark 放置一个“标记”,如 ,\tikzmark{a}然后您可以使用pic cs. 来使用该标记,如\draw (pic cs:a) -- ++(1,0);。完整的示例:

\documentclass{beamer}
\usepackage[beamer,customcolors]{hf-tikz}
\usepackage{tabularx}
\usepackage{colortbl}
\usetikzlibrary{tikzmark}

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

\begin{document}

\begin{frame}{Title}

\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   
  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}

在此处输入图片描述

目前尚不清楚您为什么要加载该hf-tikz包,因为它在您的 MWE 中没有任何作用。

相关内容