带有子标题的 minipage 环境中 tikzpicture pgf 绘图图形的垂直对齐

带有子标题的 minipage 环境中 tikzpicture pgf 绘图图形的垂直对齐

我想让这两个图形pgfplots垂直对齐,而子标题保持对齐(这就是[t]在环境中使用该选项的原因minipage)。它们的框似乎大小不同。我该怎么做?

代码:

\documentclass[a4paper,12pt,oneside]{report}
\usepackage{pgfplots}
\usepackage{a4wide} 
\usepackage{filecontents}
\usepgfplotslibrary{units}
\usepackage{graphicx}

\begin{document}

\begin{figure}[!h]
\centering
\begin{minipage}[t]{0.5\textwidth}
    \centering
    \begin{tikzpicture}[scale = 0.9]
    \begin{axis}[use units,
    xlabel=N,
    ylabel=w\textsubscript{fm}/w\textsubscript{fn},
    grid=major,
    legend style={draw=none,at={(0.77,0.25)},anchor=north,legend columns=1,column sep=5pt},
    legend cell align={left},
    ]
    \addplot+[black,mark=square*, only marks,mark size=0.7pt, mark options={scale=2,solid}] table [x=n, y=w_n, /pgf/number format/read comma as period, col sep=semicolon]{lab-seal-geometry-study.CSV};
    \end{axis}
    \end{tikzpicture}
    (a) Subcaption
\end{minipage}%
\begin{minipage}[t]{0.5\textwidth}
    \centering
    \begin{tikzpicture}[scale = 0.9]
    \begin{axis}[use units,
    x unit=mm, xlabel=C,
    ylabel=w\textsubscript{fm}/w\textsubscript{fn},
    grid=major,
    legend style={draw=none,at={(0.77,0.25)},anchor=north,legend columns=1,column sep=5pt},
    legend cell align={left},
    ]
    \addplot+[black,mark=square*, only marks,mark size=0.7pt, mark options={scale=2,solid}] table [x=c, y=w_c, /pgf/number format/read comma as period, col sep=semicolon]{lab-seal-geometry-study.CSV};

    \end{axis}
    \end{tikzpicture}
    (b) Subcaption
\end{minipage}
\caption{Caption}
\end{figure}

\end{document}

在此处输入图片描述

答案1

快速破解方法是\strut向每个xlabels 添加,例如xlabel=C\strut。这样,它们两个都具有相同的高度,因此对齐效果更好。

顺便问一下,你考虑过subcaption包及其subfigure环境吗?环境的语法与 for 相同minipage,因此你只需要在代码中将minipage其更改为。然后你就可以使用而不是。subfigure\caption{Subcaption}(a) Subcaption

在此处输入图片描述

\documentclass[a4paper,12pt,oneside]{report}
\usepackage{pgfplots}
%\usepackage{a4wide} % deprecated
\usepackage{geometry} % use geometry instead
\geometry{margin=2cm}

\usepgfplotslibrary{units}
%\usepackage{graphicx} % loaded by tikz, which is loaded by pgfplots

\usepackage{subcaption} % for subfigure env
\begin{document}

\begin{figure}[!h]
\centering
\begin{subfigure}[t]{0.5\textwidth}
    \centering
    \begin{tikzpicture}
    \begin{axis}[
    width=0.95\linewidth, % set width instead of scaling
    use units,
    xlabel=N\strut, % add strut
    ylabel=w\textsubscript{fm}/w\textsubscript{fn},
    grid=major,
    legend style={draw=none,at={(0.77,0.25)},anchor=north,legend columns=1,column sep=5pt},
    legend cell align={left},
    ]
    \addplot+[black,mark=square*, only marks,mark size=0.7pt, mark options={scale=2,solid},domain=10:24] {rnd};%table [x=n, y=w_n, /pgf/number format/read comma as period, col sep=semicolon]{lab-seal-geometry-study.CSV};
    \end{axis}
    \end{tikzpicture}
    \caption{Subcaption}
\end{subfigure}%
\begin{subfigure}[t]{0.5\textwidth}
    \centering
    \begin{tikzpicture}
    \begin{axis}[
    width=0.95\linewidth, % set width instead of scaling
    use units,
    x unit=mm, xlabel=C\strut, % add \strut here as well
    ylabel=w\textsubscript{fm}/w\textsubscript{fn},
    grid=major,
    legend style={draw=none,at={(0.77,0.25)},anchor=north,legend columns=1,column sep=5pt},
    legend cell align={left},
    ]
    \addplot+[black,mark=square*, only marks,mark size=0.7pt, mark options={scale=2,solid},domain=1:4] {rnd};% table [x=c, y=w_c, /pgf/number format/read comma as period, col sep=semicolon]{lab-seal-geometry-study.CSV};
    \end{axis}
    \end{tikzpicture}
    \caption{Subcaption}
\end{subfigure}
\caption{Caption}
\end{figure}

\end{document}

相关内容