子图中刻度标签对齐错误

子图中刻度标签对齐错误

刻度标签没有与轴对齐,但它们的对齐方式有点不同。如红色垂直线所示。

图像:

在此处输入图片描述

MWE 代码:

\documentclass[12pt, a4paper,
                parskip=half,
                toc=bibliography,
                numbers=noendperiod
               ]{scrbook}

\usepackage[hmargin={3.0cm, 2.5cm},
            vmargin={2.5cm, 2.0cm},
            includehead,    includefoot
            ]{geometry}

\usepackage[UKenglish]{babel}
\usepackage[T1]{fontenc}

\usepackage{scrlayer-scrpage}
\usepackage{subcaption}
\usepackage{caption}

\setkomafont{captionlabel}{\bfseries\rmfamily}

\usepackage[dvipsnames,table,xcdraw]{xcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage[font=normalsize]{subcaption}

\begin{document}
    \begin{figure}[ht]
            \pgfplotsset{
                     width=\linewidth, height=0.9\linewidth,
                     enlarge y limits=0.1,
                     %tick label style={font=\scriptsize},
                     xticklabel style = {text width=0.8em},
                     %ylabel style = {text width=1em, inner sep=2pt},
                     yticklabel style = {text width=2.0em, anchor= east},
                     label style={font=\bfseries\boldmath},
                     %tick label style={font=\bfseries\boldmath},
                     %
                     %tick align = outside,
                     tick pos = left,
                     %every axis plot post/.append style={color=Blue, dashed, mark=*}, 
                     }
                \begin{subfigure}[t]{0.48\linewidth}
                        \begin{tikzpicture}
                            \begin{loglogaxis}[
                            xmin=10, xmax=0.1e8,
                            ymin=1e-8, ymax=1e2,
                            xlabel={Number of Flops}, 
                            ylabel={Normalized MSE: $\log_{10} (e)$ },
                            scatter/classes={ a={mark=square*, blue}, b={mark=square*, red}, c={mark=square, black}, d={mark=triangle*, blue}, e={mark=triangle*, red},f={mark=triangle*, black},g={mark=x, black}, h={mark= diamond*, pink} },
                            ] 
                                \addplot[scatter, only marks,
                                scatter src=explicit symbolic]
                                table[meta=label] {
                                    x     y      label
                                    1320.9279232530525 0.9258769833615981 a
                                    
                                    };
                            \end{loglogaxis}
                        \end{tikzpicture}
                    \caption{Plot 1}
                \end{subfigure}
            \hfill
                \begin{subfigure}[t]{0.48\linewidth}
                    \begin{tikzpicture}
                        \begin{axis}[
                            domain=0:1,
                            ymax=1,
                            xlabel={Input $x$},
                            ylabel={$f(x)$},
                            %samples=801
                                    ]
                            \addplot[orange, mark=*] {sin(5*deg(x))};
                            \addplot[black, mark=*] {sin(10*deg(x))};
                            \legend{$\sin(5x)$,$\sin(10x)$,$\sin(50x)$}
                        \end{axis}
                    \end{tikzpicture}
                    \caption{Plot 2}
                \end{subfigure}
        
            \medskip
                \begin{subfigure}[t]{0.48\linewidth}
                    \begin{tikzpicture}
                        \begin{loglogaxis}[
                        xmin=10, xmax=0.1e8,
                        ymin=1e-13, ymax=1e1,
                        xlabel={Number of Flops}, 
                        ylabel={Normalized MSE: $\log_{10} (e)$ },
                        %label style={font=\bfseries\boldmath},
                        %tick label style={font=\bfseries\boldmath},
                        scatter/classes={ a={mark=square*, blue}, b={mark=square*, red}, c={mark=square, black}, d={mark=triangle*, blue}, e={mark=triangle*, red},f={mark=triangle*, black},g={mark=x, black}, h={mark= diamond*, pink} },
                        ] 
                            \addplot[scatter, only marks,
                            scatter src=explicit symbolic]
                                table[meta=label] {
                                    x     y      label
                                    55.57063517556737 0.28272347338878956 a
                                
                                    };                        
                        \end{loglogaxis}
                    \end{tikzpicture}
                    \caption{Plot 3}
                \end{subfigure}
            \hfill
                \begin{subfigure}[t]{0.48\linewidth}
                    \begin{tikzpicture}
                        \begin{axis}[
                            domain=0:1,
                            xlabel={Input $x$}, 
                            ylabel={$f(x)$},
                            ymin= 0, ymax=1e1,
                                    ]
                            \addplot[orange, mark=*]  {e^x)};
                            \addplot[black, mark=*]  {e^(2*x))};
                            \legend{$\exp(x)$,$\exp(2x)$}
                        \end{axis}
                    \end{tikzpicture}
                    \caption{Plot 4}
                \end{subfigure}
        \caption{caption for all plots}
        \label{all_plots}
    \end{figure}
\end{document}

答案1

编辑:

  • 根据您的评论,您希望所有图表具有相同的大小、垂直和水平居中 - 您可以通过在每个图形列中定义xtick标签的相等最小高度和相等的文本宽度来实现:ytick
  • 您可以通过使用tick label stylexticklabel style˙ 和 `yticklabel 样式来实现这一点,如下面 MWE 中所做的那样:
\documentclass[12pt, a4paper,
                parskip=half,
                toc=bibliography,
                numbers=noendperiod
               ]{scrbook}

\usepackage[hmargin={3.0cm, 2.5cm},
            vmargin={2.5cm, 2.0cm},
            includehead,    includefoot
            ]{geometry}

\usepackage[UKenglish]{babel}
\usepackage[T1]{fontenc}

\usepackage{scrlayer-scrpage}
\usepackage{subcaption}
\usepackage{caption}

\setkomafont{captionlabel}{\bfseries\rmfamily}

\usepackage[dvipsnames,table,xcdraw]{xcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}


\begin{document}
    \begin{figure}[ht]
\pgfplotsset{
     width=\linewidth, height=0.9\linewidth,
     enlarge y limits=0.1,
     tick label style={font=\footnotesize},
     xticklabel style={minimum height=3ex, anchor=north},
     yticklabel style={text width=2em, align=right},
     label style={inner sep=0pt, font=\footnotesize\bfseries\boldmath},
     legend style = {font=\footnotesize}
     }
     \begin{subfigure}[t]{0.48\linewidth}
\begin{tikzpicture}
    \begin{loglogaxis}[
        xmin=10, xmax=0.1e8,
        ymin=1e-8, ymax=1e2,
        xlabel={Number of Flops},
        ylabel={Normalized MSE: $\log_{10} (e)$ },
        scatter/classes = { a={mark=square*, blue},
                            b={mark=square*, red},
                            c={mark=square, black},
                            d={mark=triangle*, blue},
                            e={mark=triangle*, red},
                            f={mark=triangle*, black},
                            g={mark=x, black},
                            h={mark= diamond*, pink} },
                        ]
\addplot[scatter, only marks,
         scatter src=explicit symbolic]
         table[meta=label] {    x   y   label
                            1320.9279232530525 0.9258769833615981 a
                            };
    \end{loglogaxis}
\end{tikzpicture}
\caption{Plot 1}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{0.48\linewidth}
\begin{tikzpicture}
    \begin{axis}[
        yticklabel style={text width=1.7em},
        domain=0:1,
        ymax=1,
        xlabel={Input $x$},
        ylabel={$f(x)$},
                ]
\addplot[orange, mark=*] {sin(5*deg(x))};
\addplot[black, mark=*] {sin(10*deg(x))};
\legend{$\sin(5x)$,$\sin(10x)$,$\sin(50x)$}
    \end{axis}
\end{tikzpicture}
\caption{Plot 2}
    \end{subfigure}

    \medskip
\begin{subfigure}[t]{0.48\linewidth}
\begin{tikzpicture}
    \begin{loglogaxis}[
        xmin=10, xmax=0.1e8,
        ymin=1e-13, ymax=1e1,
        xlabel={Number of Flops},
        ylabel={Normalized MSE: $\log_{10} (e)$ },
        scatter/classes = { a={mark=square*, blue},
                            b={mark=square*, red},
                            c={mark=square, black},
                            d={mark=triangle*, blue},
                            e={mark=triangle*, red},
                            f={mark=triangle*, black},
                            g={mark=x, black},
                            h={mark= diamond*, pink} },
                      ]
\addplot[scatter, only marks,
         scatter src=explicit symbolic]
         table[meta=label] {    x   y   label
                            55.57063517556737 0.28272347338878956 a
                            };
    \end{loglogaxis}
\end{tikzpicture}
\caption{Plot 3}
    \end{subfigure}
\hfill
    \begin{subfigure}[t]{0.48\linewidth}
\begin{tikzpicture}
    \begin{axis}[
        yticklabel style={text width=1.7em},
        domain=0:1,
        xlabel={Input $x$},
        ylabel={$f(x)$},
        ymin= 0, ymax=1e1,
                    ]
        \addplot[orange, mark=*]  {e^x)};
        \addplot[black, mark=*]  {e^(2*x))};
        \legend{$\exp(x)$,$\exp(2x)$}
    \end{axis}
\end{tikzpicture}
\caption{Plot 4}
    \end{subfigure}
\caption{caption for all plots}
\label{all_plots}
    \end{figure}
\end{document}

在此处输入图片描述

相关内容