如何为 tikz 图片添加标题?这是我的 latex 片段:
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage[paperwidth=40cm,paperheight=16cm]{geometry}
\usepackage{atbegshi}% http://ctan.org/pkg/atbegshi
\AtBeginDocument{\AtBeginShipoutNext{\AtBeginShipoutDiscard}}
\geometry{
left=5mm,
right=5mm,
top=5mm,
bottom=5mm,
}
\begin{document}
\begin{tikzpicture}
%real picture
\node[inner sep=0pt] (realcoccus) at (0,12)
{\includegraphics[scale=0.3]{realcoccuscropped.png}};
\node[inner sep=0pt] (realbacillus) at (0,7)
{\includegraphics[scale=0.3]{realbacilluscropped.png}};
\node[inner sep=0pt] (realspirillum) at (0,2)
{\includegraphics[scale=0.22]{realspirillumcropped.png}};
\end{tikzpicture}
\end{document}
我想在每张图片下添加一个标题:
\node[inner sep=0pt] (realcoccus) at (0,12)
{\includegraphics[scale=0.3]{realcoccuscropped.png}};
\caption
不起作用。添加文本看起来很糟糕。
如何添加字幕?
谢谢
答案1
您可以\captionof
使用capt-of
或者caption
包并将标题放在所需宽度的节点内(我选择了\linewidth
,但请进行最适合您需求的调整);该positioning
库用于轻松地将标题放置在图像下方:
代码:
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{capt-of}
\begin{document}
\noindent\begin{minipage}{\linewidth}
\begin{center}
\begin{tikzpicture}
\node[inner sep=0pt] (realcoccus) at (0,12)
{\includegraphics[scale=0.3]{example-image-a}};
\node[inner sep=0pt,below=\belowcaptionskip of realcoccus,text width=\linewidth]
{\captionof{figure}{the first image}};
\node[inner sep=0pt] (realbacillus) at (0,7)
{\includegraphics[scale=0.3]{example-image-b}};
\node[inner sep=0pt,below=\belowcaptionskip of realbacillus,text width=\linewidth]
{\captionof{figure}{the second image}};
\node[inner sep=0pt] (realspirillum) at (0,2)
{\includegraphics[scale=0.3]{example-image-c}};
\node[inner sep=0pt,below=\belowcaptionskip of realspirillum,text width=\linewidth]
{\captionof{figure}{the third image}};
\end{tikzpicture}
\end{center}
\end{minipage}
\end{document}