Tikz 覆盖在 Beamer 中无法按预期工作

Tikz 覆盖在 Beamer 中无法按预期工作

考虑以下 MWE:

 % !TeX program = lualatex
    \documentclass{beamer}
    \usepackage{tikz-feynman}
    \usetheme{metropolis}           
    \title{A minimal example}
    \date{\today}
    \author{Matthias Vogelgesang}
    \institute{Centre for Modern Beamer Themes}
    \begin{document}
      \maketitle
      \section{First Section}
      \begin{frame}{First Frame}
       \begin{figure}[H]
    \begin{tabular}{cc}
        \multicolumn{2}{c}{\tikzfeynmanset{
                every plain={blue},
            }
            \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1,remember picture] {
                a  -- [plain] t1 
                -- [scalar,red] t2 
                --[plain]t3 
                -- [plain]t1,
                t2 -- [plain] p1 ,
                t3 -- [plain] p2,
            };
            \tikz[overlay,remember picture]{\path (t1) --(t2) coordinate[midway] (m1);
                \draw[thick,red] (m1) --(t1);
            }
        }\\
        \multicolumn{2}{c}{(a) $C_{PRR}$}\\[6pt]
        \tikzfeynmanset{
            every plain={blue},
        }
        \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1,remember picture] {
            a  -- [plain] t1 
            -- [scalar,red] t2 
            --[scalar,red]t3 
            -- [plain]t1,
            t2 -- [plain] p1 ,
            t3 -- [plain] p2,
        };
        \tikz[overlay,remember picture]{\path (t1) --(t2) coordinate[midway] (m1);
            \draw[thick,red] (m1) --(t1);
        }
        \tikz[overlay,remember picture]{\path (t2) --(t3) coordinate[midway] (m2);
            \draw[thick,red] (m2) --(t3);
        } &   \tikzfeynmanset{
            every plain={blue},
        }
        \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1,remember picture] {
            a  -- [plain] t1 
            -- [scalar,red] t2 
            --[scalar,red]t3 
            -- [plain]t1,
            t2 -- [plain] p1 ,
            t3 -- [plain] p2,
        };
        \tikz[overlay,remember picture]{\path (t1) --(t2) coordinate[midway] (m1);
            \draw[thick,red] (m1) --(t1);
        }
        \tikz[overlay,remember picture]{\path (t2) --(t3) coordinate[midway] (m2);
            \draw[thick,red] (m2) --(t2);
        } 
        \\
        (b) $ C_{PMR} $ & (c) $ C_{PPR} $ \\[6pt]
        \tikzfeynmanset{
            every plain={blue},
        }
        \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1,remember picture] {
            a  -- [plain] t1 
            -- [scalar,red] t2 
            --[scalar,red]t3 
            -- [scalar,red]t1,
            t2 -- [plain] p1 ,
            t3 -- [plain] p2,
        };
        \tikz[overlay,remember picture]{\path (t1) --(t2) coordinate[midway] (m1);
            \draw[thick,red] (m1) --(t1);
        }
        \tikz[overlay,remember picture]{\path (t2) --(t3) coordinate[midway] (m2);
            \draw[thick,red] (m2) --(t2);
        }
        \tikz[overlay,remember picture]{\path (t3) --(t1) coordinate[midway] (m3);
            \draw[thick,red] (m3) --(t3);
        }
        &       \tikzfeynmanset{
            every plain={blue},
        }
        \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1,remember picture] {
            a  -- [plain] t1 
            -- [scalar,red] t2 
            --[scalar,red]t3 
            -- [scalar,red]t1,
            t2 -- [plain] p1 ,
            t3 -- [plain] p2,
        };
        \tikz[overlay,remember picture]{\path (t1) --(t2) coordinate[midway] (m1);
            \draw[thick,red] (m1) --(t1);
        }
        \tikz[overlay,remember picture]{\path (t2) --(t3) coordinate[midway] (m2);
            \draw[thick,red] (m2) --(t3);
        }
        \tikz[overlay,remember picture]{\path (t3) --(t1) coordinate[midway] (m3);
            \draw[thick,red] (m3) --(t3);
        } \\
        (d) $C_{PPP}$ & (e) $ C_{PMP} $ 
    \end{tabular}
    %   \caption{caption}
\end{figure}
\end{frame}
\end{document}

以上内容产生了下图:

叠加问题

如您所见,叠加层全部堆叠在幻灯片的左下角,而不是单独应用于每个图表。请注意,此问题不会发生在文章或书籍文档类中。

如何正确应用覆盖?

答案1

只需添加即可修复您的代码

\tikzset{every picture/.append style={remember picture}}

在文档的开头。remember picture因此,所有的 s 都变得多余,

    \documentclass{beamer}
    \usepackage{tikz-feynman}
    \usetheme{metropolis}           
    \title{A minimal example}
    \date{\today}
    \author{Matthias Vogelgesang}
    \institute{Centre for Modern Beamer Themes}
    \tikzset{every picture/.append style={remember picture}}
    \begin{document}
      \maketitle
      \section{First Section}
      \begin{frame}{First Frame}
       \begin{figure}[H]
    \begin{tabular}{cc}
        \multicolumn{2}{c}{\tikzfeynmanset{
                every plain={blue},
            }
            \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1] {
                a  -- [plain] t1 
                -- [scalar,red] t2 
                --[plain]t3 
                -- [plain]t1,
                t2 -- [plain] p1 ,
                t3 -- [plain] p2,
            };
            \tikz[overlay]{\path (t1) --(t2) coordinate[midway] (m1);
                \draw[thick,red] (m1) --(t1);
            }
        }\\
        \multicolumn{2}{c}{(a) $C_{PRR}$}\\[6pt]
        \tikzfeynmanset{
            every plain={blue},
        }
        \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1] {
            a  -- [plain] t1 
            -- [scalar,red] t2 
            --[scalar,red]t3 
            -- [plain]t1,
            t2 -- [plain] p1 ,
            t3 -- [plain] p2,
        };
        \tikz[overlay]{\path (t1) --(t2) coordinate[midway] (m1);
            \draw[thick,red] (m1) --(t1);
        }
        \tikz[overlay]{\path (t2) --(t3) coordinate[midway] (m2);
            \draw[thick,red] (m2) --(t3);
        } &   \tikzfeynmanset{
            every plain={blue},
        }
        \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1] {
            a  -- [plain] t1 
            -- [scalar,red] t2 
            --[scalar,red]t3 
            -- [plain]t1,
            t2 -- [plain] p1 ,
            t3 -- [plain] p2,
        };
        \tikz[overlay]{\path (t1) --(t2) coordinate[midway] (m1);
            \draw[thick,red] (m1) --(t1);
        }
        \tikz[overlay]{\path (t2) --(t3) coordinate[midway] (m2);
            \draw[thick,red] (m2) --(t2);
        } 
        \\
        (b) $ C_{PMR} $ & (c) $ C_{PPR} $ \\[6pt]
        \tikzfeynmanset{
            every plain={blue},
        }
        \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1] {
            a  -- [plain] t1 
            -- [scalar,red] t2 
            --[scalar,red]t3 
            -- [scalar,red]t1,
            t2 -- [plain] p1 ,
            t3 -- [plain] p2,
        };
        \tikz[overlay]{\path (t1) --(t2) coordinate[midway] (m1);
            \draw[thick,red] (m1) --(t1);
        }
        \tikz[overlay]{\path (t2) --(t3) coordinate[midway] (m2);
            \draw[thick,red] (m2) --(t2);
        }
        \tikz[overlay]{\path (t3) --(t1) coordinate[midway] (m3);
            \draw[thick,red] (m3) --(t3);
        }
        &       \tikzfeynmanset{
            every plain={blue},
        }
        \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1] {
            a  -- [plain] t1 
            -- [scalar,red] t2 
            --[scalar,red]t3 
            -- [scalar,red]t1,
            t2 -- [plain] p1 ,
            t3 -- [plain] p2,
        };
        \tikz[overlay]{\path (t1) --(t2) coordinate[midway] (m1);
            \draw[thick,red] (m1) --(t1);
        }
        \tikz[overlay]{\path (t2) --(t3) coordinate[midway] (m2);
            \draw[thick,red] (m2) --(t3);
        }
        \tikz[overlay]{\path (t3) --(t1) coordinate[midway] (m3);
            \draw[thick,red] (m3) --(t3);
        } \\
        (d) $C_{PPP}$ & (e) $ C_{PMP} $ 
    \end{tabular}
    %   \caption{caption}
\end{figure}
\end{frame}
\end{document}

在此处输入图片描述

您的代码无法运行的原因是费曼图内的顶点没有被正确记住。

编辑:只是为了完整性:有一种更直接的方式来产生相同的输出:只需定义一个“新”的风格

\tikzset{semidashed straight line/.style={dashed,postaction={decorate,decoration={markings,
         mark=at position 0 with {\coordinate (X0); },
         mark=at position 0.5 with {\draw[thick,solid] (X0) -- (0,0); }}}}}

这样就不需要任何覆盖了。(在您的示例中,您可以通过将所有标量设置为这种样式来进一步简化这一点,就像您对实线重复执行的操作一样,但我个人不会这样做,因为您可能在某处需要一个真正的标量。)

    \documentclass{beamer}
    \usepackage{tikz-feynman}
    \usetikzlibrary{decorations.markings}
    \usetheme{metropolis}           
    \title{A minimal example}
    \date{\today}
    \author{Matthias Vogelgesang}
    \institute{Centre for Modern Beamer Themes}
    \tikzset{semidashed straight line/.style={dashed,postaction={decorate,decoration={markings,
     mark=at position 0 with {\coordinate (X0); },
     mark=at position 0.5 with {\draw[thick,solid] (X0) -- (0,0); }}}}}
    \begin{document}
      \maketitle
      \section{First Section}
      \begin{frame}{First Frame}
       \begin{figure}[H]
    \begin{tabular}{cc}
        \multicolumn{2}{c}{\tikzfeynmanset{
                every plain={blue},
            }
            \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1] {
                a  -- [plain] t1 
                -- [semidashed straight line,red] t2 
                --[plain]t3 
                -- [plain]t1,
                t2 -- [plain] p1 ,
                t3 -- [plain] p2,
            };
        }\\
        \multicolumn{2}{c}{(a) $C_{PRR}$}\\[6pt]
        \tikzfeynmanset{
            every plain={blue},
        }
        \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1] {
            a  -- [plain] t1 
            -- [semidashed straight line,red] t2 
            --[semidashed straight line,red]t3 
            -- [plain]t1,
            t2 -- [plain] p1 ,
            t3 -- [plain] p2,
        };
        &   \tikzfeynmanset{
            every plain={blue},
        }
        \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1] {
            a  -- [plain] t1 
            -- [semidashed straight line,red] t2 
            --[semidashed straight line,red]t3 
            -- [plain]t1,
            t2 -- [plain] p1 ,
            t3 -- [plain] p2,
        };
        \\
        (b) $ C_{PMR} $ & (c) $ C_{PPR} $ \\[6pt]
        \tikzfeynmanset{
            every plain={blue},
        }
        \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1] {
            a  -- [plain] t1 
            -- [semidashed straight line,,red] t2 
            -- [semidashed straight line,red]t3 
            -- [semidashed straight line,red]t1,
            t2 -- [plain] p1 ,
            t3 -- [plain] p2,
        };
        &       \tikzfeynmanset{
            every plain={blue},
        }
        \feynmandiagram[scale=.5,transform shape] [small, horizontal=a to t1] {
            a  -- [plain] t1 
            -- [semidashed straight line,red] t2 
            --[semidashed straight line,red]t3 
            -- [semidashed straight line,red]t1,
            t2 -- [plain] p1 ,
            t3 -- [plain] p2,
        };\\
        (d) $C_{PPP}$ & (e) $ C_{PMP} $ 
    \end{tabular}
    %   \caption{caption}
\end{figure}
\end{frame}
\end{document}

相关内容