サブ図のキャプションを中央揃えにする

サブ図のキャプションを中央揃えにする

私はしたいと思います中央揃えサブキャプションは対応するサブ図に関連しており、次のようになります。

ここに画像の説明を入力してください

私の現在の試みは、左揃え\centering対応するブロックで指定したにもかかわらずです\begin{subfigure} ... \end{subfigure}

私が望んでいるのは、サブキャプション全体をボックス。他の形式は変更しないでください。

MWE:

\documentclass{article}
\usepackage{graphicx}
\usepackage{float}
\usepackage{mwe}
\usepackage{caption}
\captionsetup{format=plain,font=small,labelfont={sc,bf},labelsep=period}
\usepackage{subcaption}
\captionsetup[subfigure]{format=hang,font=footnotesize,labelfont=up,singlelinecheck=false}
\renewcommand{\thesubfigure}{\alph{subfigure}}


\begin{document}

\begin{figure}[!htbp]
    \centering
    \begin{subfigure}[t]{0.49\textwidth}
        \centering
        \includegraphics[width=\linewidth]{example-image-a}
        \caption{
            Caption of subfigure1 \\ (e.g., load case 1 and 2).
        }
    \end{subfigure}%
    \hfill
    \begin{subfigure}[t]{0.49\textwidth}
        \centering
        \includegraphics[width=\linewidth]{example-image-b}
        \caption{
            Caption of subfigure2 \\ (e.g., load case 3 and 4).
        }
    \end{subfigure}%
    \caption{
        Comparison of two subfigures.
    }
\end{figure}

\end{document}

答え1

justification=centeringに引数 を指定する必要があります\captionsetup[subfigure]{...}。その際、引数format=hangsinglelinecheck=falseは何も役に立たないように見えるので削除したほうがよいでしょう。

\centeringまた、これら 3 つのディレクティブは、不必要なコードの乱雑さを生み出す以外何もしないので、すべて削除 (または少なくともコメント アウト) します。

ここに画像の説明を入力してください

\documentclass{article}
\usepackage{graphicx,mwe}
\usepackage{caption}
\captionsetup{format=plain,font=small,
              labelfont={sc,bf},labelsep=period}
\usepackage{subcaption}
\captionsetup[subfigure]{font=footnotesize,
              labelfont=up,
              %%singlelinecheck=false,
              %%format=hang,
              justification=centering % <-- new
             }
%\renewcommand{\thesubfigure}{\alph{subfigure}} % that's the default


\begin{document}

\begin{figure}[!htbp]
    %%\centering
    \begin{subfigure}[t]{0.49\textwidth}
        %%\centering
        \includegraphics[width=\linewidth]{example-image-a}
        \caption{Caption of subfigure 1\\(e.g., load cases 1 and 2).}
    \end{subfigure}%
    \hfill
    \begin{subfigure}[t]{0.49\textwidth}
        %%\centering
        \includegraphics[width=\linewidth]{example-image-b}
        \caption{Caption of subfigure 2\\(e.g., load cases 3 and 4).}
    \end{subfigure}%
    \caption{Comparison of two subfigures.}
\end{figure}

\end{document} 

関連情報