为什么 \tikzmark 在 \multicolumn 之前不起作用?

为什么 \tikzmark 在 \multicolumn 之前不起作用?

\tikzmark始终在单个单元格或 之前和之后\multirow以及 之后起作用\multicolumn

\multicolumn给出了错误:

! Misplaced \omit.
\multispan ->\omit 
                   \@multispan 
l.55        \tikzmark{cmc}\multicolumn{2}{c}{A and B}
                                                 & C\tikzmark{dmc} \\
I expect to see \omit only after tab marks or the \cr of
an alignment. Proceed, and I'll ignore this case.

以下是 MWE:

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{tikzmark, calc}
\usepackage{array}
\usepackage{multirow}
\renewcommand{\arraystretch}{1.4}
\begin{document}
    All these ones work:

    \begin{tabular}{ccc}
        \tikzmark{a}A & B & \tikzmark{b}C \\ 
        D & E & F \\
    \end{tabular}
    \begin{tikzpicture}[overlay,remember picture]
        \draw (pic cs:a) -- (pic cs:b);
    \end{tikzpicture}

    \begin{tabular}{ccc}
        A\tikzmark{c} & B & C\tikzmark{d} \\ 
        D & E & F \\
    \end{tabular}
    \begin{tikzpicture}[overlay,remember picture]
    \draw (pic cs:c) -- (pic cs:d);
    \end{tikzpicture}

    \begin{tabular}{ccc}
        \tikzmark{amr}\multirow{2}{*}{A and D} & B & \tikzmark{bmr}C \\ 
        & E & F\\
    \end{tabular}
    \begin{tikzpicture}[overlay,remember picture]
        \draw (pic cs:amr) -- (pic cs:bmr);
    \end{tikzpicture}

    \begin{tabular}{ccc}
        \multirow{2}{*}{A and D}\tikzmark{cmr} & B & C\tikzmark{dmr} \\ 
        & E & F\\
    \end{tabular}
    \begin{tikzpicture}[overlay,remember picture]
        \draw (pic cs:cmr) -- (pic cs:dmr);
    \end{tikzpicture}

    \begin{tabular}{ccc}
        \multicolumn{2}{c}{A and B}\tikzmark{amc} & C\tikzmark{bmc} \\ 
        D & E & F \\
    \end{tabular}
    \begin{tikzpicture}[overlay,remember picture]
        \draw (pic cs:amc) -- (pic cs:bmc);
    \end{tikzpicture}

    But this one doesn't work:

    \begin{tabular}{ccc}
        \tikzmark{cmc}\multicolumn{2}{c}{A and B} & C\tikzmark{dmc} \\ 
        D & E & F \\
    \end{tabular}
    \begin{tikzpicture}[overlay,remember picture]
    \draw (pic cs:cmc) -- (pic cs:dmc);
    \end{tikzpicture}

\end{document}

答案1

您应该将 放在\tikzmark里面,\multicolumn因为它算作文本 (\null)。OTOH \multirow只是将文本覆盖在接下来的几行上,假设行间距恒定。它与 大致相同\smash{\begin{tabular}[t]...\end{tabular}}

请注意,如果 的\multicolumn宽度超过两列,则\hfill不需要 s。

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{tikzmark, calc}
\usepackage{array}
\usepackage{multirow}
\renewcommand{\arraystretch}{1.4}
\begin{document}
    \begin{tabular}{ccc}
        \multicolumn{2}{c}{\tikzmark{cmc}\hfill A and B\hfill\null} & C\tikzmark{dmc} \\ 
        D wider & E & F \\
    \end{tabular}
    \begin{tikzpicture}[overlay,remember picture]
    \draw (pic cs:cmc) -- (pic cs:dmc);
    \end{tikzpicture}
\end{document}

演示

相关内容