![tikzpicture 无法在 subfigure/subcaption/subfloat 中绘制](https://linux22.com/image/409194/tikzpicture%20%E6%97%A0%E6%B3%95%E5%9C%A8%20subfigure%2Fsubcaption%2Fsubfloat%20%E4%B8%AD%E7%BB%98%E5%88%B6.png)
我尝试将两个 tikzpicture 放在一个图中作为两个子图,但 tikzpicture 在子图中无法正确绘制。我尝试过包 subfig、subfigure、subcaption,但都失败了。
\documentclass[UTF8]{article}
\usepackage{subfig}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\begin{tikzpicture}
\datavisualization [school book axes, visualize as line]
data [headline={x, y}] {
0, 0
1, 1
2, 1
3, 0
};
\end{tikzpicture}
\begin{figure*}[!t]
\centering
\subfloat[Case I]{\begin{tikzpicture}
\datavisualization [school book axes, visualize as line]
data [headline={x, y}] {
0, 0
1, 1
2, 1
3, 0
};
\end{tikzpicture}%
\label{fig_first_case}}
\hfil
\subfloat[Case II]{\begin{tikzpicture}
\datavisualization [school book axes, visualize as line]
data [headline={x, y}] {
0, 0
1, 1
2, 1
3, 0
};
\end{tikzpicture}%
\label{fig_second_case}}
\caption{Simulation results for the network.}
\label{fig_sim}
\end{figure*}
\end{document}
答案1
为了说明我的评论:
当然,它似乎只影响 tikzpicture,而不影响 subfloat(它使用保存框来测量宽度)。重新定义 \sbox 和 \savebox 也无济于事。
\documentclass[UTF8]{article}
\usepackage{subfig}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\sbox0{\begin{tikzpicture}
\datavisualization [school book axes, visualize as line]
data [headline={x, y}] {
0, 0
1, 1
2, 1
3, 0
};
\end{tikzpicture}}\usebox0% does not work right
\setbox0=\hbox{\begin{tikzpicture}
\datavisualization [school book axes, visualize as line]
data [headline={x, y}] {
0, 0
1, 1
2, 1
3, 0
};
\end{tikzpicture}}\usebox0
\begin{figure}[t]
\centering
\subfloat[Case I]{\usebox0
\label{fig_first_case}}
\hfil
\subfloat[Case II]{\usebox0
\label{fig_second_case}}
\caption{Simulation results for the network.}
\label{fig_sim}
\end{figure}
\end{document}