在 Beamer 中,如何为 tikz 节点内的图形添加标题?

在 Beamer 中,如何为 tikz 节点内的图形添加标题?

我以为我会找到答案这里,但在这种特殊情况下,该解决方案似乎不起作用......

一般来说:如何在 tikz 节点内放置图​​形标题?我制作了以下 MWE,但这不是我在演示文稿中使用的布局,只是一个随机的布局,所以我需要一个通用的解决方案,而不仅仅是针对这个例子...

在这个例子中,我只想在图 B 的正下方放置一个标题,我该怎么做?

梅威瑟:

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\usepackage[labelformat=empty,font=scriptsize,skip=0pt,
justification=raggedright,singlelinecheck=false]{caption}

\begin{document}

\begin{frame}
    \begin{figure}
    \begin{tikzpicture}[remember picture, every node/.style={inner sep=0,outer sep=0}]

    \node[anchor=west] (A) at (0,0) {\includegraphics[width=2.25cm]{example-image-a}};

    \node[right=0.75cm of A.east, anchor=west] (B) {\includegraphics[width=2.25cm]{example-image-b}
        %\captionof{figure}{my caption here}%I was hoping this would work...
    };
    \node[below=\belowcaptionskip of B,text width=\linewidth]
    {\captionof{figure}{my caption here}};%And this doesn't work either...

    \node [right=0.75cm of B.east, anchor=west] (C) {\includegraphics[width=2.25cm]{example-image-c}};

    \node [below=0.75cm of A.south east, anchor=north west] (D) {\includegraphics[width=2.25cm]{example-image}};

    \node [right=0.75cm of D.east, anchor=west] (E) {\includegraphics[width=2.25cm]{example-image}};

    \node [right=0.75cm of E.east, anchor=west] (F) {\includegraphics[width=2.25cm]{example-image}};
    \end{tikzpicture}
    \end{figure}
\end{frame}

\end{document}

生成:

如图

答案1

在这种情况下,当您的标题只有一行时,您无需使用caption包和figure环境即可获得所需的结果:

\documentclass{beamer}
\usepackage{lmodern,tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{frame}
    \begin{center}
    \begin{tikzpicture}[node distance=2mm and 5mm]
\node              (A)  {\includegraphics[width=2.25cm]{example-image-a}};
\node [right=of A] (B)  {\includegraphics[width=2.25cm]{example-image-b}};
\node [right=of B] (C)  {\includegraphics[width=2.25cm]{example-image-c}};
    \node (capt) [below=of B,text width=\linewidth, align=center,font=\scriptsize]
                        {my caption here};
\node [below=of A |- capt.south] (D) {\includegraphics[width=2.25cm]{example-image}};
\node [right=of D] (E)  {\includegraphics[width=2.25cm]{example-image}};
\node [right=of E] (F)  {\includegraphics[width=2.25cm]{example-image}};
    \end{tikzpicture}
    \end{center}
\end{frame}
\end{document}

在此处输入图片描述

但是,你可以将 TikZ 图片分成两部分:

\documentclass{beamer}
\usepackage{lmodern,tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{frame}
    \begin{figure}\centering
    \begin{tikzpicture}[node distance=2mm and 5mm]
\node              (A)  {\includegraphics[width=2.25cm]{example-image-a}};
\node [right=of A] (B)  {\includegraphics[width=2.25cm]{example-image-b}};
\node [right=of B] (C)  {\includegraphics[width=2.25cm]{example-image-c}};
    \end{tikzpicture}
\caption{my caption here}
    \begin{tikzpicture}[node distance=2mm and 5mm]
\node              (D) {\includegraphics[width=2.25cm]{example-image}};
\node [right=of D] (E)  {\includegraphics[width=2.25cm]{example-image}};
\node [right=of E] (F)  {\includegraphics[width=2.25cm]{example-image}};
    \end{tikzpicture}
    \end{figure}
\end{frame}
\end{document}

如果你不喜欢在标题中添加Figure标签,你只需要caption相应地设置模板,例如添加到序言中:

\setbeamerfont{caption}{size=\scriptsize}
\setbeamertemplate{caption}{\insertcaption\par}

附录: 我不清楚 TikZ 节点的用途。你可以将节点中的图像排列成与以前没有节点时相同的框架形式:

\documentclass{beamer}
\setbeamerfont{caption}{size=\scriptsize}
\setbeamertemplate{caption}{\insertcaption\par}

\begin{document}
\begin{frame}
    \begin{figure}\centering
\includegraphics[width=2.25cm]{example-image-a}\hfil
\includegraphics[width=2.25cm]{example-image-b}\hfil
\includegraphics[width=2.25cm]{example-image-c} 

\caption{my caption here}

\includegraphics[width=2.25cm]{example-image}\hfil
\includegraphics[width=2.25cm]{example-image}\hfil
\includegraphics[width=2.25cm]{example-image}
    \end{figure}
\end{frame}
\end{document}

框架形象与以前相同,但代码更加简洁。

答案2

使用包justification=centering中的选项caption

\documentclass{beamer}
\usepackage{lmodern,tikz}
\usetikzlibrary{positioning,calc}
\usepackage[labelformat=empty,font=scriptsize,skip=0pt,
justification=centering,singlelinecheck=false]{caption}

\begin{document}
\begin{frame}
    \begin{figure}\centering    
    \begin{tikzpicture}
    \node [anchor=west] (A) at (0,0) {\includegraphics[width=2.25cm]{example-image-a}};
    \node [right=0.75cm of A.east, anchor=west] (B) {\includegraphics[width=2.25cm]{example-image-b}};
    \node [below=\belowcaptionskip of B,text width=\linewidth]{\captionof{figure}{my caption here}};    
    \node [right=0.75cm of B.east, anchor=west] (C) {\includegraphics[width=2.25cm]{example-image-c}};
    \node [below=0.75cm of A.south, anchor=north] (D) {\includegraphics[width=2.25cm]{example-image}};
    \node [right=0.75cm of D.east, anchor=west] (E) {\includegraphics[width=2.25cm]{example-image}};
    \node [right=0.75cm of E.east, anchor=west] (F) {\includegraphics[width=2.25cm]{example-image}};    
    \end{tikzpicture}
    \end{figure}
\end{frame}
\end{document}

在此处输入图片描述

相关内容