移动 tikzpicture 时,Tikzmarks 被任意放置

移动 tikzpicture 时,Tikzmarks 被任意放置

我想让tikzpicture所有幻灯片的画布居中,以便可以一致地定位对象。出于某种原因,当我添加shift=(current page.center)到所有tikzpicture图片环境时,tikzmark我使用的标记定位非常随意。我尝试提炼下面的 MWE 来复制这种奇怪的行为。

\documentclass[xcolor={svgnames}]{beamer}

\usetheme{boxes}
\useoutertheme{infolines}

\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

% I tried this, but it didn't work.
%\tikzset{%
%  every picture/.append style={%
%        shift=(current page.center)
%        }}

\begin{frame}
  \begin{itemize}
    \item \tikzmark{a} abcd
    \item abcd
    \item abcd
  \end{itemize}
  % Including shift in the options causes the tikzmark to move arbitrarily.
  \begin{tikzpicture}[remember picture,overlay]%,shift=(current page.center)]
    \node at (current page.center) {o};
    \node at (pic cs:a) {tikz-a};
  \end{tikzpicture}

\end{frame}

\end{document}

这是我不移动时的样子tikzpicturetikzmark 做正确的事

现在我这样做了。

tikzmark 失败

如果我将移位附加到 ,我会得到相同的行为tikzpicture;我这样做的目的是让它tikzmark也适当地移动 的坐标。

我也发现有趣的是,两种情况下的页面中心(标有“o”)是相同的;然而,对于我尝试制作的幻灯片来说,这通常不是真的。

最后,我使用的是 1.0 版本tikzmark加拿大运输安全局

答案1

percusse 是正确的:tikzmark 的明显偏移是 pic cs 坐标系返回的坐标的实际偏移。节点坐标通过显式反转矩阵并将其应用于坐标,然后再将其返回到解析器来解决这个问题。

pic这是变换不变的坐标系的修改版本。

\documentclass[xcolor={svgnames}]{beamer}

\usetheme{boxes}
\useoutertheme{infolines}

\usepackage{tikz}
\usetikzlibrary{tikzmark}

\makeatletter
\tikzdeclarecoordinatesystem{pic}{%
  \pgfutil@in@,{#1}%
  \ifpgfutil@in@%
    \tmk@labeldef#1\@nil
  \else
    \tmk@labeldef#1,(0pt,0pt)\@nil
  \fi
  \@ifundefined{save@pt@\tmk@label}{%
    \tikz@scan@one@point\pgfutil@firstofone\tmk@def
  }{%
      \pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
      \pgfsys@getposition{\pgfpictureid}\save@this@pic%
      \pgf@process{\pgfpointorigin\save@this@pic}%
      \pgf@xa=\pgf@x
      \pgf@ya=\pgf@y
      \pgf@process{\pgfpointorigin\save@orig@pic}%
      \advance\pgf@x by -\pgf@xa
      \advance\pgf@y by -\pgf@ya
      \pgf@xa=\pgf@x
      \pgf@ya=\pgf@y
      \@ifundefined{save@pg@\csname save@pt@\tmk@label\endcsname}{}{%
        \@ifundefined{save@pg@\pgfpictureid}{}{%
          \pgfkeysvalueof{/tikz/next page vector}%
          \advance \pgf@xa by \csname save@pg@\csname save@pt@\tmk@label\endcsname\endcsname\pgf@x\relax
\advance \pgf@ya by \csname save@pg@\csname save@pt@\tmk@label\endcsname\endcsname\pgf@y\relax
          \advance \pgf@xa by -\csname save@pg@\pgfpictureid\endcsname\pgf@x\relax
\advance \pgf@ya by -\csname save@pg@\pgfpictureid\endcsname\pgf@y\relax
        }%
      }%
\pgf@x=\pgf@xa
\pgf@y=\pgf@ya
      \pgftransforminvert%
      \pgf@pos@transform{\pgf@x}{\pgf@y}%
    }%
  }
\makeatother

\begin{document}

% I tried this, but it didn't work.
\tikzset{%
  every picture/.append style={%
        shift=(current page.center),
scale=.5
        }}

\begin{frame}
  \begin{itemize}
    \item \tikzmark[\coordinate(mark)]{a}abcd
    \item abcd
    \item abcd
  \end{itemize}
  % Including shift in the options causes the tikzmark to move arbitrarily.
  \begin{tikzpicture}[remember picture,overlay]%,shift=(current page.center)]
\node (p) at (0,0) {O};
\node (q) at (0pt,0pt) {Q};
    \node at (current page.center) {o};
\begin{scope}[xshift=1cm]
    \node at (pic cs:a) {tikz-a};
\end{scope}
\node at (mark) {mark};
  \end{tikzpicture}

\tikzset{every picture/.style = {}}
\begin{tikzpicture}[remember picture,overlay]
\draw[->] (0,0) -- (p);
\draw[->] (0,0) -- (pic cs:a);
\end{tikzpicture}

\end{frame}

\end{document}

未修改的 tikzmark

相关内容