
我以為我會找到答案這裡,但該解決方案似乎在這種特殊情況下不起作用...
一般來說:如何在 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}