使用 tikzmark 后表格单元格内容对齐发生了变化?

使用 tikzmark 后表格单元格内容对齐发生了变化?
\usepackage{tikz}
\newcommand\tikzmark[2]{%
\tikz[remember picture,overlay,baseline=0pt] 
\node[inner sep=0pt,outer sep=0pt, anchor=base] (#1){#2};%
}

\newcommand\link[2]{%
\begin{tikzpicture}[remember picture, overlay, >=stealth, shorten >= 10pt, shorten <=10pt]
  \draw[->] (#1.south east) to (#2.north west);
\end{tikzpicture}%
}


\begin{table}[htbp]
\renewcommand{\arraystretch}{1}
\setlength{\tabcolsep}{10pt}
\centering
\begin{tabular}{m{0.2in} | m{0.2in} m{0.2in} m{0.2in} m{0.2in} m{0.2in} m{0.2in} m{0.2in} m{0.2in} m{0.2in}}
    \hline
    & A  & B   & C       & B       & B       & B       & D  & C  & E \\
    \hline
 C  & 0   & 0  & \tikzmark{13}{\bf{1}}  & 0       & 0       & 0       & 0  & 1  & 0 \\

 B  & 0   & 1  & 0       & \tikzmark{12}{\bf{2}}  & \tikzmark{22}{\bf{1}}  & 1       & 0  & 0  & 0 \\

 B  & 0   & 1  & 0       & 1       & \tikzmark{11}{\bf{3}}  & \tikzmark{21}{\bf{2}}  & 0  & 0  & 0 \\

 C  & 0   & 0  & 1  & 0  & 0  & 0  & 0  & 1  & 0 \\

 E  & 0   & 0  & 0  & 0  & 0  & 0  & 0  & 0  & 1 \\
   \hline
\end{tabular}
 \captionsetup{justification=centering}
 \caption{All local alignment scoring matrix}
 \label{table:all_local}
\end{table}

\link{11}{12}
\link{12}{13}
\link{21}{22}

在此处输入图片描述

答案1

您不需要定义\tikzmark命令,因为有一个 tikzlibrarytikzmark可以为您完成此操作。

请注意\bf,已弃用,我已改用\textbf{...}

此外,由于您尚未发布完整的 mwe,我添加了编译它所需的代码(\documentclass、包等),也许这与您的不一致。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{array}
\usepackage{caption}

\newcommand{\memo}[2]{%
    \tikzmark{#1}\textbf{#2}
}

\newcommand{\link}[2]{%
    \begin{tikzpicture}[remember picture, overlay, >=stealth, shorten >=9pt, shorten <=3pt]
        \draw [->] ([yshift=3pt]{pic cs:#1}) -- ([yshift=6pt]{pic cs:#2});
    \end{tikzpicture}
}
\begin{document}
\begin{table}[htbp]
    \renewcommand{\arraystretch}{1.5}% I've also increased this for esthetic reasons
    \setlength{\tabcolsep}{10pt}
    \centering
    \begin{tabular}{m{0.2in} | m{0.2in} m{0.2in} m{0.2in} m{0.2in} m{0.2in} m{0.2in} m{0.2in} m{0.2in} m{0.2in}}
        \hline
        & A  & B   & C       & B       & B       & B       & D  & C  & E \\
        \hline
        C  & 0   & 0  & \memo{13}{1} & 0       & 0       & 0       & 0  & 1  & 0 \\

        B  & 0   & 1  & 0       & \memo{12}{2} & \memo{22}{1} & 1       & 0  & 0  & 0 \\

        B  & 0   & 1  & 0       & 1       & \memo{11}{3} & \memo{21}{2} & 0  & 0  & 0 \\

        C  & 0   & 0  & 1  & 0  & 0  & 0  & 0  & 1  & 0 \\

        E  & 0   & 0  & 0  & 0  & 0  & 0  & 0  & 0  & 1 \\
        \hline
    \end{tabular}
    \captionsetup{justification=centering}
    \caption{All local alignment scoring matrix}
    \label{table:all_local}
\end{table}

\link{11}{12}
\link{12}{13}
\link{21}{22}

\end{document}

在此处输入图片描述

相关内容