tikz 覆盖相对于方程

tikz 覆盖相对于方程

在页面以外的环境上覆盖 tikz 输出的最简单方法是什么?

下面代码的顶部是一个将一些 tikz 输出放在页面特定位置的示例。对于方程式等其他结构,如何做到这一点?(代码底部)

该示例针对的是方程式和图像,但问题旨在具有普遍性。

\documentclass{article}


\usepackage{graphicx}
\usepackage{tikz}
\usepackage{tikzpagenodes}


\begin{document}



\begin{tikzpicture}[remember picture,overlay,shift={(current page.south west)}]  % works
\node[anchor=south west] (0,0) {\includegraphics[width=\paperwidth,height=\paperheight]{pig}};
\end{tikzpicture}

\clearpage

\begin{equation}  
 z=x+y
 \begin{tikzpicture}[remember picture,overlay,shift={(current equation.south west)}]
 \node[anchor=south west] (0,0) {\includegraphics[width=\equationwidth,height=\equationheight]{pig}};
 \end{tikzpicture}
\end{equation}


\end{document}

答案1

不用说,我不得不使用“猪”以外的图像。第一个将方程式放在 tikzpicture 中,而第二个将 tikzpicture 放在方程式中。

\documentclass{article}

\usepackage{graphicx}
\usepackage{tikz}

\newlength{\equationwidth}
\newlength{\equationheight}

\begin{document}

\noindent\begin{tikzpicture}[baseline]
   \node[inner sep=0pt] (current equation)
     {\begin{minipage}{\textwidth}\begin{equation} z=x+y\end{equation}\end{minipage}};
   \pgfextractx{\equationwidth}{\pgfpointdiff{\pgfpointanchor{current equation}{west}}%
     {\pgfpointanchor{current equation}{east}}}%
   \pgfextracty{\equationheight}{\pgfpointdiff{\pgfpointanchor{current equation}{south}}%
     {\pgfpointanchor{current equation}{north}}}%
   \node[opacity=0.6,inner sep=0pt] at (current equation)
     {\includegraphics[width=\equationwidth,height=\equationheight]{example-image}};
\end{tikzpicture}

\begin{equation}  
 \begin{tikzpicture}[baseline]
   \node[anchor=base] (current equation) {$\displaystyle z=x+y$};
   \pgfextractx{\equationwidth}{\pgfpointdiff{\pgfpointanchor{current equation}{west}}%
     {\pgfpointanchor{current equation}{east}}}%
   \pgfextracty{\equationheight}{\pgfpointdiff{\pgfpointanchor{current equation}{south}}%
     {\pgfpointanchor{current equation}{north}}}%
   \node[opacity=0.6] at (current equation)
     {\includegraphics[width=\equationwidth,height=\equationheight]{example-image}};
 \end{tikzpicture}
\end{equation}
\noindent\rule{\textwidth}{1pt}% check alignment

\end{document}

演示


以下操作相同,只是将方程式放在图像的顶部。

\documentclass{article}

\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{backgrounds}

\newlength{\equationwidth}
\newlength{\equationheight}

\begin{document}

\noindent\begin{tikzpicture}[baseline]
   \node[anchor=base,inner sep=0pt] (current equation)
     {\begin{minipage}{\textwidth}\begin{equation} z=x+y\end{equation}\end{minipage}};
   \pgfextractx{\equationwidth}{\pgfpointdiff{\pgfpointanchor{current equation}{west}}%
     {\pgfpointanchor{current equation}{east}}}%
   \pgfextracty{\equationheight}{\pgfpointdiff{\pgfpointanchor{current equation}{south}}%
     {\pgfpointanchor{current equation}{north}}}%
   \begin{scope}[on background layer]
     \node[inner sep=0pt] at (current equation)
       {\includegraphics[width=\equationwidth,height=\equationheight]{example-image}};
   \end{scope}
\end{tikzpicture}

\begin{equation}  
 \begin{tikzpicture}[baseline]
   \node[anchor=base] (current equation) {$\displaystyle z=x+y$};
   \pgfextractx{\equationwidth}{\pgfpointdiff{\pgfpointanchor{current equation}{west}}%
     {\pgfpointanchor{current equation}{east}}}%
   \pgfextracty{\equationheight}{\pgfpointdiff{\pgfpointanchor{current equation}{south}}%
     {\pgfpointanchor{current equation}{north}}}%
   \begin{scope}[on background layer]
     \node[inner sep=0pt] at (current equation)
       {\includegraphics[width=\equationwidth,height=\equationheight]{example-image}};
   \end{scope}
 \end{tikzpicture}
\end{equation}
\noindent\rule{\textwidth}{1pt}% check alignment

\end{document}

相关内容