如何对子图中的标题进行连字符连接?

如何对子图中的标题进行连字符连接?

我有一个居中的子图,其中包含 2 幅图像和 2 个标题,如下所示

人物

它们由以下代码制作

\documentclass[12pt,a4paper]{article}
\usepackage[a4paper,margin=1in]{geometry}

 \begin{figure}[H]
 \begin{center}
      \begin{subfigure}[t]{0.4\textwidth}
          \includegraphics[width=\textwidth]{04 Introduction/figurer/Quiescent_galaxies_allz_UVJ_classic.png}
          \caption{Quiescent galaxies in UVJ colors from the Classic catalog plotted against redshift in bins of approximately 2 billion years.}
          \label{fig:cq_uvj}
      \end{subfigure}
      \hfill
      \begin{subfigure}[t]{0.4\textwidth}
          \includegraphics[width=\textwidth]{04 Introduction/figurer/Quiescent_galaxies_allz_UVJ_farmer.png}
          \centering\caption{\hspace{0pt} Quiescent galaxies in UVJ colors from the Farmer catalog plotted against redshift in bins of approximately 2 billion years.}
          \label{fig:fq_uvj}
      \end{subfigure}
         \caption{}
         \label{fig:cfq_uvj}
 \end{center}
 \end{figure}

但是,每张图片的标题都没有连字符。我该如何拆分单词,让它们整齐地对齐?

答案1

如果您加载该ragged2e包,选项justfication=RaggedRight(请注意两个大写的 R 字母)将变为可用。和\captionsetup之间的区别在于前者允许对标题文本进行连字符连接。justfication=RaggedRightjustfication=raggedright

在此处输入图片描述

\documentclass[demo]{article} % omit 'demo' option in real document

\usepackage{graphicx,subcaption,ragged2e}
% abandon full justification of caption text, but allow hyphenation:
\captionsetup[subfigure]{justification=RaggedRight} 

\begin{document}

\begin{figure}[ht]
\begin{subfigure}[t]{0.45\textwidth}
  \includegraphics[width=\linewidth]{04 Introduction/figurer/Quiescent_galaxies_allz_UVJ_classic.png}
  \caption{Quiescent galaxies in UVJ colors from the Classic catalogue, plotted against redshift in bins of approximately 2 billion years.}
  \label{fig:cq_uvj}
\end{subfigure}%
\hfill
\begin{subfigure}[t]{0.45\textwidth}
  \includegraphics[width=\linewidth]{04 Introduction/figurer/Quiescent_galaxies_allz_UVJ_farmer.png}
  \caption{Quiescent galaxies in UVJ colors from the Farmer catalogue, plotted against redshift in bins of approximately 2 billion years.}
  \label{fig:fq_uvj}
\end{subfigure}
\caption{}
\label{fig:cfq_uvj}
\end{figure}

\end{document}

答案2

  • 请始终(如果可能)提供 MWE(最小工作示例),即一个可以重现您的问题的小型完整文档。
  • 您的代码片段很奇怪。不要使用center环境(这会引入额外的垂直空间),而要使用命令\centering
  • 不要在标题中插入格式。

编辑: 正如您在评论中所说,问题的根源是设置\captionsetup{justification=centering}。这不是有问题的代码片段的一部分显然您需要单独的设置subfigure。现在将两者都添加到以下 MWE 中即可得到您所要求的内容:

\documentclass{article}
\usepackage{graphicx}
\usepackage[justification=centering]{caption}
\usepackage[justification=justified]{subcaption}

\begin{document}
    \begin{figure}[ht]
    \centering
    \setkeys{Gin}{width=\linewidth}
\begin{subfigure}[t]{0.4\textwidth}
\includegraphics{example-image-duck}
\caption{Quiescent galaxies in UVJ colors from the Classic catalog plotted against redshift in bins of approximately 2 billion years.}
\label{fig:cq_uvj}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.4\textwidth}
\includegraphics{example-image-duck}
\caption{Quiescent galaxies in UVJ colors from the Farmer catalog plotted against red shift in bins of approximately 2 billion years.}
\label{fig:fq_uvj}
\end{subfigure}
    \caption{my figure}
    \label{fig:cfq_uvj}
    \end{figure}
\end{document}

在此处输入图片描述

相关内容