在 xaxis 中将 tikzpicture 或 caption (并排) 与 subfloat 和逗号分隔符对齐时出现问题

在 xaxis 中将 tikzpicture 或 caption (并排) 与 subfloat 和逗号分隔符对齐时出现问题

当我在 x 轴上定位两个带有 subfloat 和逗号分隔数字格式的 tikzpicture 时,我遇到了标题对齐问题。有人能解决这个问题吗? 字幕之间的高度差异

以下是 MWE:

\documentclass{article}
\usepackage{caption,subfig}
\usepackage{pgfplots}

\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
}

\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotsset{width=0.45\textwidth, height=.25\textheight}
\subfloat[Caption 1 Caption 1 Caption 1 Caption 1 Caption 1]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=0,
    xmax=1.80,
    ymin=0,
    ymax=60000,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 10000};
    \addlegendentry{\(x^3 + 3x + 10000\)}   
\end{axis}
\end{tikzpicture}
}%
\hfil
\subfloat[Caption 2 Caption 2 Caption 2 Caption 2 Caption 2]{%
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=-25,
    xmax=25,
    ymin=0,
    ymax=100,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 1};
    \addlegendentry{\(x^3 + 3x + 1\)}
\end{axis}
\end{tikzpicture}
}%
\caption{Caption 3}
\end{figure}

\end{document}

答案1

使用包subfigure中的环境subcaption而不是subfig

\documentclass{article}
\usepackage{subcaption}
\usepackage{pgfplots}
\usetikzlibrary{calc}

\pgfplotsset{
   compat=newest,
   /pgf/number format/use comma,
}

\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotsset{width=0.95\linewidth, height=.25\textheight}
\begin{subfigure}[b]{0.45\textwidth}
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=0,
    xmax=1.80,
    ymin=0,
    ymax=60000,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 10000};
    \addlegendentry{\(x^3 + 3x + 10000\)}   
\end{axis}
\end{tikzpicture}
\caption{Caption 1 Caption 1 Caption 1 Caption 1 Caption 1% For testing
\begin{tikzpicture}[remember picture] \coordinate(a);\end{tikzpicture}}
\end{subfigure}%
\hfil
\begin{subfigure}[b]{0.45\textwidth}
\begin{tikzpicture}[baseline]
\begin{axis}[
    xmin=-25,
    xmax=25,
    ymin=0,
    ymax=100,
    xlabel={label x},
    ylabel={label y}
    ]
    \addplot {x^3 + 3*x + 1};
    \addlegendentry{\(x^3 + 3x + 1\)}
\end{axis}
\end{tikzpicture}
\caption{Caption 2 Caption 2 Caption 2 Caption 2 Caption 2% For testing
\begin{tikzpicture}[remember picture] \coordinate(b);\end{tikzpicture}}
\end{subfigure}%
\caption{Caption 3}
\end{figure}

%Testing
\begin{tikzpicture}[remember picture,overlay]
\draw[red] (a)--(b);
\draw[blue] ($(a)+(0,-0.1)$)--++(6,0);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容