為什麼 \tikzmark 在 \multicolumn 之前不起作用?

為什麼 \tikzmark 在 \multicolumn 之前不起作用?

\tikzmark始終在單一儲存格或 a 之前和之後\multirow以及 a 之後工作\multicolumn

a\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)。 \multirow假設行間距恆定,OTOH 只是將文字覆蓋在接下來的幾行上。與 大致相同\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}

示範

相關內容