註解表格

註解表格

我試圖透過突出顯示和註釋最後一列來註釋表格,但是一旦我將其\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 中支付任何費用。

相關內容