![如何在 tikzpicture 中放置子标题?](https://linux22.com/image/321957/%E5%A6%82%E4%BD%95%E5%9C%A8%20tikzpicture%20%E4%B8%AD%E6%94%BE%E7%BD%AE%E5%AD%90%E6%A0%87%E9%A2%98%EF%BC%9F.png)
我在 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}