我在迷你页面中并排放置了两张图片,但它们的标题是左对齐的,而我希望它们居中。我尝试了在这里找到的各种解决方案,但似乎对我不起作用。有人能给出建议吗?
\documentclass[]{report}
\usepackage{graphicx}
\usepackage{float}
\usepackage[a4paper, bottom=3cm]{geometry} % useful for page dimensions
\usepackage{caption}
\usepackage[capitalise]{cleveref}
\begin{document}
\begin{figure}
\centering
\begin{minipage}[t][7cm]{0.5\textwidth}
\centering
\includegraphics[scale=0.6]{/Users/bethlong/Documents/University/PhD/Thesis/Figures/APrimeVisibleDecayConstraints.png}
\caption{Constraints on visible dark\\ photon decays}
\label{fig:APrimeVisibleDecayConstraints}
\end{minipage}%
\begin{minipage}[t][7cm]{0.5\textwidth}
{\centering
\includegraphics[scale=0.6]{/Users/bethlong/Documents/University/PhD/Thesis/Figures/APrimeInvisibleDecayConstraints.png}
\caption{Constraints on invisible\\ dark photon decays}}
\label{fig:APrimeInvisibleDecayConstraints}
\end{minipage}
\end{figure}
\end{document}
答案1
目前还不完全清楚,标题应该如何居中:
- 因此,所有标题都应具有相同的样式,还是只有小页面中的这两种样式?
- 如何居中:
- 仅标题文本的最后一行或
- 完整的字幕吗?
作为回答,我假设,此图中的标题有自己的风格,与其他标题不同。
\documentclass{report}
\usepackage[a4paper, bottom=3cm]{geometry} % useful for page dimensions
\usepackage{graphicx}
\usepackage{caption}
\usepackage[capitalise]{cleveref}
\begin{document}
\begin{figure}[ht]
\captionsetup{justification=centerlast}
% \captionsetup{justification=centering}
\centering
\begin{minipage}{0.48\textwidth}
\centering
\includegraphics[width=\linewidth]{example-image-a.png}
\captionof{figure}{Constraints on visible dark photon decays}
\label{fig:APrimeVisibleDecayConstraints}
\end{minipage}%
\hfill
\begin{minipage}{0.48\textwidth}
\centering
\includegraphics[width=\linewidth]{example-image-b.png}
\captionof{figure}{Constraints on invisible dark photon decays}
\label{fig:APrimeInvisibleDecayConstraints}
\end{minipage}
\end{figure}
\end{document}
和\captionsetup{justification=centerlast}
:
和\captionsetup{justification=centering}
:
答案2
\documentclass[]{report}
\usepackage{graphicx}
\usepackage{float}
\usepackage[a4paper, bottom=3cm]{geometry} % useful for page dimensions
\usepackage{caption}
\usepackage[capitalise]{cleveref}
\begin{document}
\begin{figure}
\centering
\begin{minipage}{0.45\textwidth}
\centering
\includegraphics[scale=0.49]{example-image-a.png}
\captionof{figure}{Constraints on visible dark photon decays}
\label{fig:APrimeVisibleDecayConstraints}
\end{minipage}%
\hfill
\begin{minipage}{0.45\textwidth}
\centering
\includegraphics[scale=0.49]{example-image-b.png}
\captionof{figure}{Constraints on invisible dark photon decays}
\label{fig:APrimeInvisibleDecayConstraints}
\end{minipage}
\end{figure}
\end{document}
答案3
我猜你希望图形的标题与图形的 y 轴对齐。有两种方法可以实现这一点。一种是使用包subcaption
(正如我在评论中提到的)。另一种是使用floatrow
包,它与包兼容caption
,并提供了一些强大的工具来操作图形、表格和标题。
在本 MWE 中,我使用了这两个选项。我没有使用minipage
变通方法,因为这两个选项都提供了将两个图形并排放置的更好方法。
\documentclass[11pt]{article}
\usepackage[a4paper,margin={25mm,25mm}]{geometry}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{caption}
\usepackage[labelformat=simple]{subcaption} % <= offers subfigure and subcaptions options
\captionsetup{labelfont={bf,sf,small},labelsep=endash,box=colorbox,boxcolor=yellow!50,slc=off,textfont={color=blue},}
\captionsetup[sub]{labelsep=endash}
% \DeclareCaptionSubType*[arabic]{figure}
\renewcommand{\thesubfigure}{Figure \thefigure.\arabic{subfigure}}
\usepackage{floatrow}
\floatsetup[figure]{floatrowsep=columnsep}
\setlength\columnsep{10mm}
\begin{document}
Captions centered using \verb*|\subcaption{}| and \verb*|\subcaptionbox{}| :
\begin{figure}[!h]
\captionsetup[sub]{width*=.4\textwidth,margin={8mm,2mm}}
\subcaptionbox{Constraints on visible dark photon decay. \label{sfig:visible}}[.45\textwidth]{\includegraphics[width=.4\textwidth]{visible_dphoton_decay.jpg}}
\subcaptionbox{Constraints on invisible dark photon decay. \label{sfig:invisible}}[.45\textwidth]{\includegraphics[width=.4\textwidth]{invisible_dphoton_decay.jpg}}
\caption{Constraints on dark photon decay.} \label{fig:decay}
\end{figure}
The plots in figure \ref{fig:decay} show decay of visible dark photons (\subref{sfig:visible}) on the left and of invisible dark photons (\ref{sfig:invisible}) on the right.
Captions centered using \verb*|floatrow| environment:
\begin{figure}[!h]
\captionsetup[sub]{width*=.4\textwidth,margin={8mm,2mm}}
\ffigbox{
\begin{subfloatrow}[2]
\ffigbox[\FBwidth]
{\subcaption{Constraints on visible dark photon decay. \label{frfig:visible}}}
{\includegraphics[width=.4\textwidth]{visible_dphoton_decay.jpg}}
\ffigbox[\FBwidth]
{\subcaption{Constraints on invisible dark photon decay. \label{frfig:invisible}}}
{\includegraphics[width=.4\textwidth]{invisible_dphoton_decay.jpg}}
\end{subfloatrow}
}
{\caption{Constraints on dark photon decay.} \label{frfig:decay}}
\end{figure}
In figure \ref{frfig:decay} the same two dacays are present in \subref{frfig:visible} (visible) and \ref{frfig:invisible} (invisible).
\end{document}
此 MWE 产生以下 PDF(请注意,图形标题仍然使用图形浮点数的整个线宽):
请注意现在引用子图的方式已经生效。使用常规\ref{}
选项将为您提供对总图的正确引用,但会导致在子图前面放置一个数字。要正确引用子图,请使用\subref{}
。此行为是由重新定义\thesubfigure
序言中的计数器引起的。当您注释掉该行并取消注释其上方的行时,子图仍以阿拉伯语计数,但没有前缀数字。