我需要对齐我的两个图。它们似乎被文本以外的其他东西固定住了。因为一个 pgfplot 的标题文本比另一个多,所以它偏移了它。请看图片。我尝试搜索,并且看到了示例,但是floatrow
对于图像(不是 pgfplots),我尝试使用floatrow
,但出现了超时错误。此外,有没有办法让两个图共享一个图例,也许位于横跨两个图(水平)的底部?
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage{pgfplots}
\usepackage{array}
\usepackage{xcolor}
\usepackage{siunitx}
\usepackage{fixltx2e}
\usepackage{tikz}
\usepackage{lscape}
\usepackage{diagbox}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{floatrow}
\usepackage[version=4]{mhchem}
\begin{figure}[h]
\begin{subfigure}{0.4\linewidth}
\centering
\begin{tikzpicture}[scale=0.95,trim left]
\begin{axis}[
width=\textwidth,
scale only axis,
xlabel={nm},
ylabel={Abs},
xmin=385, xmax=485,
legend pos=south east,
cycle list name=color list,
legend columns=2,
legend cell align=left,
legend style={font=\footnotesize},
xtick pos=left,
ytick pos=left]
\addplot table [col sep=comma, x=nm, y=0] {ST038deriv.csv};
\addplot table [col sep=comma, x=nm, y=2.3] {ST038deriv.csv};
\addplot table [col sep=comma, x=nm, y=3.5] {ST038deriv.csv};
\addplot table [col sep=comma, x=nm, y=5.2] {ST038deriv.csv};
\addplot table [col sep=comma, x=nm, y=7.8] {ST038deriv.csv};
\addplot table [col sep=comma, x=nm, y=11.7] {ST038deriv.csv};
\addplot table [col sep=comma, x=nm, y=17.6] {ST038deriv.csv};
\addplot table [col sep=comma, x=nm, y=26.3] {ST038deriv.csv};
\addplot table [col sep=comma, x=nm, y=39.5] {ST038deriv.csv};
\addplot table [col sep=comma, x=nm, y=59.3] {ST038deriv.csv};
\addplot table [col sep=comma, x=nm, y=88.9] {ST038deriv.csv};
\addplot table [col sep=comma, x=nm, y=133.3] {ST038deriv.csv};
\addplot table [col sep=comma, x=nm, y=200] {ST038deriv.csv};
\addplot table [col sep=comma, x=nm, y=300] {ST038deriv.csv};
\end{axis}
\end{tikzpicture}
\caption{$t_{initial}$ derivative abs. spectra}
\end{subfigure} %second subfigure
\hfill
\begin{subfigure}{0.4\linewidth}
\centering
\begin{tikzpicture}[scale=0.95,trim left]
\begin{axis}[
width=\textwidth,
scale only axis,
xlabel={nm},
ylabel={Abs},
xmin=385, xmax=485,
legend pos=south east,
cycle list name=color list,
legend columns=2,
legend cell align=left,
legend style={font=\footnotesize},
xtick pos=left,
ytick pos=left]
\addplot table [col sep=comma, x=nm, y=0] {ST041 re-check deriv.csv};
\addplot table [col sep=comma, x=nm, y=2.3] {ST041 re-check deriv.csv};
\addplot table [col sep=comma, x=nm, y=3.5] {ST041 re-check deriv.csv};
\addplot table [col sep=comma, x=nm, y=5.2] {ST041 re-check deriv.csv};
\addplot table [col sep=comma, x=nm, y=7.8] {ST041 re-check deriv.csv};
\addplot table [col sep=comma, x=nm, y=11.7] {ST041 re-check deriv.csv};
\addplot table [col sep=comma, x=nm, y=17.6] {ST041 re-check deriv.csv};
\addplot [densely dashed] table [col sep=comma, x=nm, y=26.3] {ST041 re-check deriv.csv};
\addplot table [col sep=comma, x=nm, y=39.5] {ST041 re-check deriv.csv};
\addplot table [col sep=comma, x=nm, y=59.3] {ST041 re-check deriv.csv};
\addplot table [col sep=comma, x=nm, y=88.9] {ST041 re-check deriv.csv};
\addplot table [col sep=comma, x=nm, y=133.3] {ST041 re-check deriv.csv};
\addplot table [col sep=comma, x=nm, y=200] {ST041 re-check deriv.csv};
\addplot table [col sep=comma, x=nm, y=300] {ST041 re-check deriv.csv};
\end{axis}
\end{tikzpicture}
\caption{$t \approx 96 hr$ derivative abs. spectra}
\end{subfigure}
\end{figure}
\end{document}
答案1
您可以尝试使用环境的可选参数subfigure
,这样图像将按顶部、底部或中心对齐。可选参数的可能值为b
、t
或c
。例如,使用b
:
\begin{subfigure}[b]{.45\linewidth}
\end{subfigure}\hill
\begin{subfigure}[b]{.45\linewidth}
\end{subfigure}
\subcaptionbox
可以使用以下方法获得不同的对齐选项:subcaption
包,它根据子图和子表的第一个标题行自动对齐子图和子表:
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage{pgfplots}
\usepackage{array}
\usepackage{xcolor}
\usepackage{siunitx}
\usepackage{fixltx2e}
\usepackage{tikz}
\usepackage{lscape}
\usepackage{diagbox}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[version=4]{mhchem}
\begin{document}
\begin{figure}[h]
\subcaptionbox{$t_{\text{initial}}$ derivative abs. spectra}{%
\begin{tikzpicture}[scale=0.95,trim left]
\begin{axis}[
width=0.45\textwidth,
scale only axis,
xlabel={nm},
ylabel={Abs},
xmin=385, xmax=485,
legend pos=south east,
cycle list name=color list,
legend columns=2,
legend cell align=left,
legend style={font=\footnotesize},
xtick pos=left,
ytick pos=left]
\addplot coordinates {(400,0) (430,8)};
\end{axis}
\end{tikzpicture}}\hfill
\subcaptionbox{$t \approx 96 hr$ derivative abs. spectra}{%
\begin{tikzpicture}[scale=0.95,trim left]
\begin{axis}[
width=0.4\textwidth,
scale only axis,
xlabel={nm},
ylabel={Abs},
xmin=385, xmax=485,
legend pos=south east,
cycle list name=color list,
legend columns=2,
legend cell align=left,
legend style={font=\footnotesize},
xtick pos=left,
ytick pos=left]
\addplot[blue] coordinates {(400,5) (470,2)};
\end{axis}
\end{tikzpicture}}
\caption{A common legend for both plots}
\end{figure}
\end{document}
结果:
至于另一个要求,即常见的图例,由于没有提供其他信息,我只是使用了\caption
。