标题上方的子图

标题上方的子图

我希望子图正好位于标题上方,但现在它却位于标题的左侧。

在此处输入图片描述

\begin{figure}[H]
\centering
\begin{subfigure}{0.45\textwidth}
\includegraphics[scale=0.7]{astmdowel}
\caption{} \label{fig:}
\end{subfigure}
\hspace*{0cm} % separation between the subfigures
\hfill
\begin{subfigure}{0.45\textwidth}
\includegraphics[scale=0.7]{BSdowel}
\caption{} \label{fig:}
\end{subfigure}
\caption{Specimen according to: a)ASTM D 5764 -97a b)BS EN 383:2007.} \label{fig:40}
\end{figure}

感谢您的评论,我使用 fbox 检查过,图片没有多余的空间:

在此处输入图片描述

以下是工作示例:

\documentclass[12pt, a4paper]{report}
% ctrl+T comment, ctrl+U uncomment
\usepackage{tikz}
\usepackage{slashbox}
\usepackage{caption}
\usepackage{float}
\usepackage{enumerate}
\usepackage{bm}

\usepackage[export]{adjustbox}

\usepackage{multirow}
\usepackage{array}

\usepackage[labelformat=simple]{subcaption}
\renewcommand\thesubfigure{\alph{subfigure})}

\usepackage{fixltx2e}
\captionsetup[subfigure]{skip=1pt} %%global setting for subfigure
\usepackage{amsmath, siunitx} 



\usepackage{xcolor}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage[labelfont=it]{caption}
\usepackage[font=it]{caption}

%\usepackage{showframe}% http://ctan.org/pkg/showframe
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd{\@makechapterhead}{\vspace*{50\p@}}{}{}{}% Removes space above \chapter head
\patchcmd{\@makeschapterhead}{\vspace*{50\p@}}{}{}{}% Removes space above \chapter* head
\makeatother


\pretolerance=10000 % stop latex from braking the words
\tolerance=2000 % stop latex from braking the words
\emergencystretch=10pt % stop latex from braking the words
\usepackage{titlesec}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{geometry}
 \geometry{a4paper,
bottom=25mm,
right=31.7mm,
 left=31.7mm,
 top=25mm,
 }
\DeclareMathSizes{10}{10}{10}{10}


\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{}{18pt}{\Huge}



\begin{document}

\begin{figure}[H]
\centering
\begin{subfigure}{0.45\textwidth}
\fbox{\includegraphics[scale=0.7]{astmdowel}}

\caption{} \label{fig:}
\end{subfigure}
\hspace*{0cm} % separation between the subfigures
\hfill
\begin{subfigure}{0.45\textwidth}
\fbox{\includegraphics[scale=0.7]{BSdowel}}
\caption{} \label{fig:}
\end{subfigure}
\caption{Specimen according to: a)ASTM D 5764 -97a b)BS EN 383:2007.} \label{fig:40}
\end{figure}

\end{document}

答案1

即使使用您原来的序言,我也无法重现您的问题。

由于其中有很多包captionsubcaption并且使用不一致的选项多次加载,因此我首先清理它,然后评论所有包和您的定义这些对于展示您的形象来说不是必需的,并且使caption选项subcaption保持一致。

第二步,我对包含的图形做了一些小改动。这里我建议改用选项 option scalewidth它可以更好地处理页面上图像的居中(使用它会有小的偏移 - 图像会稍微向左移动)。

完整代码为:

\documentclass[12pt, a4paper]{report}
% ctrl+T comment, ctrl+U uncomment
%\usepackage{tikz}
%\usepackage{slashbox}
%\usepackage{enumerate}
%\usepackage{bm}
%\usepackage[export]{adjustbox}

%\usepackage{array}
%\usepackage{booktabs}
%\usepackage{multirow}

%\usepackage{amsmath}
%\DeclareMathSizes{10}{10}{10}{10}

\usepackage{graphicx}
%\usepackage{float}
\usepackage[font=it]{caption}
\usepackage[labelformat=brace]{subcaption}
%\captionsetup[subfigure]{skip=1pt} %%global setting for subfigure
%\usepackage{siunitx}

%\usepackage{xcolor}

%\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
%\makeatletter
%\patchcmd{\@makechapterhead}{\vspace*{50\p@}}{}{}{}% Removes space above \chapter head
%\patchcmd{\@makeschapterhead}{\vspace*{50\p@}}{}{}{}% Removes space above \chapter* head
%\makeatother

%\pretolerance=10000 % stop latex from braking the words
%\tolerance=2000 % stop latex from braking the words
%\emergencystretch=10pt % stop latex from braking the words
%\usepackage{titlesec}

\usepackage{geometry}
\geometry{  a4paper,
            bottom=25mm,
            right=31.7mm,
            left=31.7mm,
            top=25mm,
            showframe% <-- for show page layout
            }

%\titleformat{\chapter}[display]
%{\normalfont\huge\bfseries}{}{18pt}{\Huge}


\begin{document}
    \begin{figure}%[htb]% <-- changed
    \centering
\begin{subfigure}{0.45\textwidth}% <-- changed
\includegraphics[width=\linewidth]{example-image-a}% <-- changed to example image
\caption{} \label{fig:}
\end{subfigure}
\hfil% <-- changed 
\begin{subfigure}{0.45\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\caption{} \label{fig:}
\end{subfigure}
\caption{Specimen according to: a)ASTM D 5764 -97a b)BS EN 383:2007.} \label{fig:40}
    \end{figure}
\end{document}

结果:

在此处输入图片描述

我建议您首先使用原始图像在 MWE 上进行测试。如果您没有获得相同定位的图像,那么您的图像中就会出现一些非常奇怪的东西。

相关内容