0

In the next code, I use a macro without parameter, that doesn't complain until I use multicolumn in it.

l.40 \TabTikzMark*{3} \hline ? ^C! Interruption. \@preamble ...begin \ignorespaces \@sharp \unskip \relax \d@llarend \hfil > \h...

l.40 \TabTikzMark*{3} \hline

The goal is to have the tikzmarks on each corners of each boxes of the table.

enter image description here

\documentclass{article}
\usepackage{tikz,array,xparse}

\usetikzlibrary{tikzmark}

\newcounter{TabTikzCount}

\makeatletter

\NewDocumentCommand{\TabTikzMark}{sm}{%
    \IfBooleanTF{#1}{%
        \\[-\ht\@arstrutbox]\noalign{\setcounter{TabTikzCount}{1}}%
        \Row{3}
        \\[-\dp\@arstrutbox]%
        }{%
        \\[-\ht\@arstrutbox]
        \Row{3}
        \\[-\dp\@arstrutbox]}}

\makeatother

\newcommand{\Row}[1]{%
%\def\MyRow{\tikzmark{\Alph{TabTikzCount}0}}%
\def\MyRow{\multicolumn{1}{@{c@{}}}\begingroup\tikzmark{\Alph{TabTikzCount}0}}%
\foreach \n [evaluate=\n as \m using int(\n-1)] in {2,...,#1} {%
\let\tikzmark\relax%
%\xdef\MyRow{\MyRow\strut\hfill\tikzmark{\Alph{TabTikzCount}\m}}%
\xdef\MyRow{\MyRow\strut\hfill\tikzmark{\Alph{TabTikzCount}\m}%
\endgroup&\multicolumn{1}{@{c@{}}}\begingroup}%
}%
\MyRow\hfill\tikzmark{\Alph{TabTikzCount}#1}\endgroup%
\stepcounter{TabTikzCount}}

\begin{document}

essai

\begin{tabular}{|c|c|c|}
\TabTikzMark*{3}\hline
a&z&a\TabTikzMark{3}\hline
a&z&a\TabTikzMark{3}\hline
\end{tabular}

essai

\tikz[overlay,remember picture]\draw[->] (pic cs:A0) -- (pic cs:C3) ;

\end{document}

Edit : It can be done with lualatex, but there is a strange shift in tikzmarks. I post a new question on that.

enter image description here

\documentclass{article}
\usepackage{tikz,array,xparse,luacode}

\usetikzlibrary{tikzmark}
\newcounter{TabTikzCount}

\makeatletter
\NewDocumentCommand{\TabTikzMark}{sm}{%
    \IfBooleanTF{#1}{%
        \\[-\ht\@arstrutbox]\noalign{\setcounter{TabTikzCount}{1}}%
        \Row{3}
        \\[-\dp\@arstrutbox]%
        }{%
        \\[-\ht\@arstrutbox]
        \Row{3}
        \\[-\dp\@arstrutbox]}}
\makeatother

\begin{luacode}
function row (s)
    a = "\\multicolumn{1}{@{}c@{}}{\\tikzmark{\\Alph{TabTikzCount}0}"
    for i = 1,s-1
    do
    a=a.."\\strut\\hfill\\tikzmark{\\Alph{TabTikzCount}"..i.."}}&\\multicolumn{1}{@{}c@{}}{"
    end
    a=a.."\\strut\\hfill\\tikzmark{\\Alph{TabTikzCount}"..s.."}}"
    tex.print (a)
    print (a)
end
\end{luacode}

\newcommand{\Row}[1]{%
\directlua{row(#1)}
\stepcounter{TabTikzCount}}

\begin{document}

\begin{tabular}{|c|c|c|c|}
\TabTikzMark*{4}\hline
a&z&a&d\TabTikzMark{4}\hline
a&z&a&d\TabTikzMark{4}\hline
\end{tabular}

\foreach \j in {A,B,C} {%
\foreach \i in {0,...,5} {%
    \tikz[overlay,remember picture]
        \node at (pic cs:\j\i) {\tiny \j\i} ;
}}

\end{document}
4
  • \tikzmark inside \xdef doesn’t seem like a good idea
    – egreg
    Mar 4, 2018 at 10:41
  • It seems to work thanks to \relax, the problem comes with the multicolums ans the begin and end groups. I've left the comented lines without the multicolums stuff.
    – Tarass
    Mar 4, 2018 at 10:45
  • You cannot hope that \multicolumn{1}{...}\begingroup...\endgroup works, can you?
    – egreg
    Mar 4, 2018 at 11:00
  • I thought that begingroup stand for {. I will work on your answer later. Thank you.
    – Tarass
    Mar 4, 2018 at 11:48

1 Answer 1

1

Not a full answer, as it is very unclear what you're about.

The syntax

\multicolumn{1}{@{c@{}}}\begingroup...\endgroup

is completely wrong. You can't delimit standard arguments with \begingroup and \endgroup.

What you can do is, maybe, adding

\protected\def\mymulti\begingroup#1\endgroup{%
  \multicolumn{1}{@{}c@{}}{#1}%
}

and use \mymulti\begingroup...\endgroup in your code.

5
  • I don't understand how to use this command, because the problem is the same. My foreach loop cut the command in two parts : at each turn first close the previous multicolumn then & sign and finally opening of the next multicolumn.
    – Tarass
    Mar 4, 2018 at 12:11
  • @Tarass That is not possible, macro arguments cannot be split at the execution level. Mar 4, 2018 at 12:29
  • @Tarass The problem is that \def already starts a cell.
    – egreg
    Mar 4, 2018 at 13:11
  • @HeikoOberdiek it can be done with lualatex, see my edit (not the spliting, but the entire command line).
    – Tarass
    Mar 4, 2018 at 16:32
  • @egreg you speak about the parasite verticales lines ?
    – Tarass
    Mar 4, 2018 at 16:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .