为什么 `align` 会破坏 `tikz` 节点放置?

为什么 `align` 会破坏 `tikz` 节点放置?

我想在文档中做一些标记,并将这些标记的描述放在边缘区域中,一个接一个。

它工作正常,但是如果我在align环境内放置一个标记,相应的节点就会垂直放错位置。

\documentclass{article}
\usepackage[a5paper,textwidth=9cm]{geometry}
\usepackage{tikzpagenodes}
\makeatletter
\protected\def\note#1{%
  \textcolor{red}{!}%
  \ifmeasuring@\else % do nothing during the measuring phase
    \tikzpicture[remember picture,overlay]
        \@ifundefined{pgf@sh@ns@note}
            {\coordinate (pos) at (0,0-|current page marginpar area.north west);}
            {\coordinate (pos) at (note.south west);}
        \node (note) [anchor=north west,inner sep=0pt,text=red] at (pos) {#1};
        \draw[red] (note.south west) rectangle (note.north east);
    \endtikzpicture
  \fi}
\makeatother
\usepackage{amsmath}
\usepackage{tabu}
\begin{document}
Some text, more\note{text 1st} text, even more text.
\begin{displaymath}
    a+b+c =\note{math 1st} d+e+f = g+h
\end{displaymath}
Some text, more\note{text 2nd} text, even more text.
\begin{align}
    a+b+c &=\note{align 1st} d+e+f \\
    &= g\note{align 2nd}+h
\end{align}
Some text, more\note{text 3rd} text, even more text.
\begin{center}
    \begin{tabu}{|c|c|c|}
        \hline
        Column 1&Column 2\note{tabu 1st}&Column3\\\hline
        Cell 1&Cell 2&Cell 3\\\hline
        Cell 4&Cell 5\note{tabu 2nd}&Cell 6\\\hline
    \end{tabu}
\end{center}
Some text, more\note{text 4th} text, even more text.
\end{document}

姆韦

tabu如果我使用表格环境,也会发生同样的事情。同时displaymath不会tabular造成任何伤害。

是什么原因?

编辑:包含tabu在 MWE 中

答案1

我真的不知道,但您看到的空间可能是保留的,并没有被填充,因为对align内容进行了两次遍历,丢弃了第一次遍历的结果,只保留了第二阶段用于调整列大小的测量值。您可以通过仅在最终排版阶段设置图片来解决此问题,而不是在amsmath测量显示部分时设置图片:

\documentclass{article}
\usepackage[a5paper,textwidth=9cm]{geometry}
\usepackage{tikzpagenodes}
\makeatletter
\protected\def\note#1{%
  \textcolor{red}{!}%
  \ifmeasuring@\else % do nothing during the measuring phase
    \tikzpicture[remember picture,overlay]
        \@ifundefined{pgf@sh@ns@note}
            {\coordinate (pos) at (0,0-|current page marginpar area.north west);}
            {\coordinate (pos) at (note.south west);}
        \node (note) [anchor=north west,inner sep=0pt,text=red] at (pos) {#1};
        \draw[red] (note.south west) rectangle (note.north east);
    \endtikzpicture
  \fi}
\makeatother
\usepackage{amsmath}
\begin{document}
Some text, more\note{text 1st} text, even more text.
\begin{displaymath}
    a+b+c =\note{math 1st} d+e+f = g+h
\end{displaymath}
Some text, more\note{text 2nd} text, even more text.
\begin{align}
    a+b+c &=\note{math 2nd} d+e+f \\
    &= g+h
\end{align}
Some text, more\note{text 3rd} text, even more text.
\end{document}

在此处输入图片描述

相关内容