我在 tikzpicture 中放了几张图片。现在我想为每张图片添加一个子标题。这怎么可能?我也试过了,\captionof
但也没用。
最小不工作示例:
\documentclass[12pt]{article}
\usepackage{caption,subcaption,tikz}
\usetikzlibrary{positioning}
\begin{document}
asdf
\begin{figure}[t]
\centering
\begin{tikzpicture}[font=\small]
\node (a){\includegraphics[width=5cm]{example-image-a}};
\node [below= of a]{\subcaption{hello}\label{subfig:hi}};
\end{tikzpicture}
\caption{caption}
\label{fig:captionlabel}
\end{figure}
\end{document}
答案1
您必须使用text width
作为节点选项或使用\parbox
(或minipage
)以便位于\captionof
组内。
\documentclass[12pt]{article}
\usepackage{caption,subcaption,tikz}
\usetikzlibrary{positioning}
\begin{document}
asdf
\begin{figure}[t]
\centering
\begin{tikzpicture}[font=\small]
\node[draw,inner sep=0pt] (a){\includegraphics[width=5cm]{example-image-a}};
\node [below= 1ex of a.south,inner sep=0pt]{\parbox{\linewidth}{\captionof{subfigure}{hello\label{subfig:hi}}}};
\end{tikzpicture}
\caption{caption}
\label{fig:captionlabel}
\end{figure}
\end{document}
答案2
你是指这样的吗?
\documentclass{article}
\usepackage{subcaption}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[red] (0,0) circle (3pt);
\end{tikzpicture}
\caption{Simple \texttt{tikz} picture}
\label{fig:TikzSimple}
\end{figure}
\begin{figure}
\begin{subfigure}[b]{.5\linewidth}
\centering\large A
\caption{A subfigure}
\label{subfig:SubfigureLeft}
\end{subfigure}%
\begin{subfigure}[b]{.5\linewidth}
\centering\large B
\caption{Another subfigure}
\label{subfig:SubfigureRight}
\end{subfigure}
\caption{Example from the \texttt{subcaption} manual, page 5}
\label{fig:SubfigureManuel}
\end{figure}
\begin{figure}
\begin{subfigure}[b]{.5\linewidth}
%
\centering
\begin{tikzpicture}
\filldraw[red] (0,0) circle (3pt);
\end{tikzpicture}
%
\caption{A subfigure}
\label{subfig:CombinationLeft}
\end{subfigure}%
\begin{subfigure}[b]{.5\linewidth}
%
\centering
\begin{tikzpicture}
\filldraw[blue] (0,0) circle (3pt);
\end{tikzpicture}
%
\caption{Another subfigure}
\label{subfig:CombinationRight}
\end{subfigure}
\caption{Combination of \figurename~\ref{fig:TikzSimple} and \ref{fig:SubfigureManuel}.}
\label{fig:Combination}
\end{figure}
\end{document}