tikzmark — 后缀使用失败

tikzmark — 后缀使用失败

我尝试将 tikzmarks 放在表格中,为了防止出现具有相同名称的 tikzmarks,我在每个表格中使用不同的前缀来创建 tikzmarks,但之后如何使用它们?

在此处输入图片描述

\documentclass[10pt]{article}
\usepackage{calc,array,tikz,xparse,siunitx,amsmath}
\usetikzlibrary{tikzmark}

\def\CS{pic cs:}

% suffix : different for each tabular
\newcounter{TabEq}

% tikzmark name : different on each line of a tabular
\newcounter{ResEq}[TabEq]

% extra space for \dfrac
\newcommand{\vtab}[1][1.2]{\rule[-0.9em*\real{#1}]{0pt}{2.3em*\real{#1}}}


\NewDocumentEnvironment{arrayl}{sO{rcl}}%
    {\setlength{\arraycolsep}{1.5pt}%
    % new suffix in each new table
    \stepcounter{TabEq}
    \IfBooleanTF{#1}{%
        $\left\{\begin{array}{#2}}{%
        $\begin{array}[t]{#2}}%
    }%
    {\end{array}%
    \IfBooleanTF{#1}{\right.$}{$}%
    }%

% I prefer not to use it as global, beacause of interraction with
% other tikzmarks in defferent context, but even with a global
% tikzset it dosen't properly.

\tikzset{tikzmark suffix={-\theTabEq}}

\newcommand{\EqFleche}[1]{%
    \begin{tikzpicture}[blue,
        % as in the marmot's related example, but locally
        overlay,
        remember picture,
        %tikzmark suffix={-\theTabEq} % local use
        ]
    \foreach \Label [count=\i from 1,
            evaluate=\i as \j using int(\i+1)]
            in {#1} {%
        % arrow on a left side between to lines
        \draw[-stealth,
            shorten >= 2pt,
            shorten <= 2pt] (\CS L\i)
                to [out=200,in=165,looseness=1.8] 
            node[midway,anchor=east] {\footnotesize$\Label$}
            (\CS L\j) ;
        % arrow on a right side between to lines
        \draw[-stealth,
            shorten >= 1,
            shorten <= 1] (\CS R\i)
                to [out=-15,in=20,looseness=1.8] 
            node[midway,anchor=west] {\footnotesize$\Label$}
            (\CS R\j) ;
    } ;
    \end{tikzpicture}%
}


% nouveau \hfill dans un tableau sinon clash avec colortab
\newcommand{\hfilll}{\hspace{0pt plus 1filll}}

% tikzmark on the left side - prefix L
\newcommand{\EqL}{\tikzmark
    %[tikzmark suffix={-\theTabEq}] % local use
    {L\theResEq}\hfilll}

% tikzmark on the right side - prefix R
\newcommand{\EqR}{\hfilll\tikzmark
    %[tikzmark suffix={-\theTabEq}] %local use
    {R\theResEq}%
    % step the line counter
    \stepcounter{ResEq}}

\pagestyle{empty}

\begin{document}

% a table with tikzmark left and right on each lines
\qquad \begin{arrayl}[>{\EqL}r@{}>{{}}l<{\EqR}]
4x-5    &= 7 \\
4x      &= 12 \\
x       &= 3 \\
\end{arrayl}

We are in tabular \theTabEq.
% put the arrows on the sides :
\EqFleche{+5,\div4}

But the arrow are alsewhere ...

\medskip

% idem
\qquad \begin{arrayl}[>{\EqL}r@{}>{{}}l<{\EqR}]
7x+3    &= 9-3x \\
10x+3   &= 9 \\
10x     &= 6 \\
x       &= \num{.6} \\
\end{arrayl}

\EqFleche{+3x,-3,\div10}

\medskip

\qquad \begin{arrayl}[>{\EqL}r@{}>{{}}l<{\EqR}]
\dfrac{x}{2}-3  &=  12\\
\smash[t]{\vtab}\dfrac{x}{2}    &=  15\\
x               &=  30\\
\end{arrayl}

\EqFleche{+3,\times2}

\end{document}

答案1

我的法语英语不太好,但我希望已经改正了。我只移动了一个计数器,并在代码中标记了它。

在此处输入图片描述

\documentclass[10pt]{article}
\usepackage{calc,array,tikz,xparse,siunitx,amsmath}
\usetikzlibrary{tikzmark}

\def\CS{pic cs:}

\newcounter{TabEq}

\newcounter{ResEq}[TabEq]

% extra space for \dfrac
\newcommand{\vtab}[1][1.2]{\rule[-0.9em*\real{#1}]{0pt}{2.3em*\real{#1}}}


\NewDocumentEnvironment{arrayl}{sO{rcl}}%
    {\setlength{\arraycolsep}{1.5pt}%
    % new suffix in each new table
    \stepcounter{TabEq}
    \IfBooleanTF{#1}{%
        $\left\{\begin{array}{#2}}{%
        $\begin{array}[t]{#2}}%
    }%
    {\end{array}%
    \IfBooleanTF{#1}{\right.$}{$}%
    }%

\tikzset{tikzmark suffix={-\theTabEq}}

\newcommand{\EqFleche}[1]{%
    \begin{tikzpicture}[blue,
        % as in the marmot's related example, but locally
        overlay,
        remember picture,
        %tikzmark suffix={-\theTabEq} % local use
        ]
    \foreach \Label [count=\i from 0, %<- this is the only thing I changed
            evaluate=\i as \j using int(\i+1)]
            in {#1} {%
        % arrow on a left side between to lines
        \draw[-stealth,
            shorten >= 2pt,
            shorten <= 2pt] ([yshift=1.1mm]\CS L\i)
                to [out=200,in=165,looseness=1.8] 
            node[midway,anchor=east] {\footnotesize$\Label$}
            ([yshift=1.3mm]\CS L\j) ;
        % arrow on a right side between to lines
        \draw[-stealth,
            shorten >= 1,
            shorten <= 1] ([yshift=1.1mm]\CS R\i)
                to [out=-15,in=20,looseness=1.8] 
            node[midway,anchor=west] {\footnotesize$\Label$}
            ([yshift=1.3mm]\CS R\j) ;
    } ;
    \end{tikzpicture}%
}


% new \hfill since original clashes with colortab
\newcommand{\hfilll}{\hspace{0pt plus 1filll}}

% tikzmark on the left side - prefix L
\newcommand{\EqL}{\tikzmark
    %[tikzmark suffix={-\theTabEq}] % local use
    {L\theResEq}\hfilll}

% tikzmark on the right side - prefix R
\newcommand{\EqR}{\hfilll\tikzmark
    %[tikzmark suffix={-\theTabEq}] %local use
    {R\theResEq}%
    % step the line counter
    \stepcounter{ResEq}}

\pagestyle{empty}

\begin{document}

% a table with tikzmark left and right on each lines
\qquad \begin{arrayl}[>{\EqL}r@{}>{{}}l<{\EqR}]
4x-5    &= 7 \\
4x      &= 12 \\
x       &= 3 \\
\end{arrayl}

We are in tabular \theTabEq.
\EqFleche{+5,\div4}

And the arrows are where they should be.

\medskip

\qquad \begin{arrayl}[>{\EqL}r@{}>{{}}l<{\EqR}]
7x+3    &= 9-3x \\
10x+3   &= 9 \\
10x     &= 6 \\
x       &= \num{.6} \\
\end{arrayl}

\EqFleche{+3x,-3,\div10}

\medskip

\qquad \begin{arrayl}[>{\EqL}r@{}>{{}}l<{\EqR}]
\dfrac{x}{2}-3  &=  12\\
\smash[t]{\vtab}\dfrac{x}{2}    &=  15\\
x               &=  30\\
\end{arrayl}

\EqFleche{+3,\times2}

\end{document}

相关内容