为图片添加标题和来源,使标题居中,来源与图片左侧对齐

为图片添加标题和来源,使标题居中,来源与图片左侧对齐

我有一个相当令人讨厌的论文指导方针需要遵循,但不幸的是我无法用我的 LATEX 技能来满足它。

我需要将图片的标题居中,并且该标题可能是多行文本。我还需要添加源,但源必须位于标题上方。对我来说,真正困难的部分是满足源必须与图片对齐的规则,位于左侧(而不是页面边缘)。

此外,如果不太麻烦的话,源和标题之间的垂直间距应该是 6pt(MS Word 单位)。

下面的代码是我尝试遵循指南的。第二张图片只是检查标题编号是否一致。

\documentclass{article}

\usepackage{graphicx}
\usepackage{float}

\usepackage[justification=centering]{caption}

\newcommand*{\captionsource}[2]{%
    
    \captionsetup{labelformat=empty}
    \caption{Source: {#2}}
    \addtocounter{figure}{-1}
    \captionsetup{labelformat=original}
    \caption{ {#1} }
} %


\begin{document}
    \begin{figure}[H]
        \centering
        \includegraphics[scale=0.3]{eta-carinae.jpg}
        \captionsource{Caption text of the image, with more than one line of text, centered, I'll just be filling with text until it overflows to next line.}{A source with ref, cite or free text.}
        \label{Source with cite.}
    \end{figure}


    \begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{crab-nebula.jpg}
    \captionsource{Caption text of the image, with more than one line of text, centered, I'll just be filling with text until it overflows to next line.}{A source with ref, cite or free text.}
    \label{Source with cite.}
\end{figure}

\end{document}

% Image sources:    
% Eta Carinae https://pt.wikipedia.org/wiki/Eta_Carinae#/media/Ficheiro:EtaCarinae.jpg
% Crab Nebula:  
% https://en.wikipedia.org/wiki/File:Crab_Nebula.jpg

这是所需的输出:

所需的 LATEX 代码输出。

答案1

我假设源标题始终与图形宽度相同且左对齐。我宁愿不使用两个\caption命令,因为它会使您的图形列表变得庞大。以下是将图形和源放在\parbox与图形宽度相同的位置的解决方案。

\documentclass{article}

\usepackage{graphicx}
\usepackage{float}

\usepackage[justification=centering,skip=6pt]{caption}

\newcommand{\graphicsandsource}[2]{%
\sbox0{#1}\parbox{\wd0}{#1\par Source: #2}
}


\begin{document}
    \begin{figure}[H]
        \centering\graphicsandsource{\includegraphics[scale=0.3]{example-image-a}}{A source with ref, cite or free text.} 
        \caption{Caption text of the image, with more than one line of text, centered, I'll just be filling with text until it overflows to next line.}
        \label{Source with cite1.}
    \end{figure}


    \begin{figure}[H]
    \centering\graphicsandsource{\includegraphics[scale=0.5]{example-image-b}}{A source with ref, cite or free text.} 
    \caption{Caption text of the image, with more than one line of text, centered, I'll just be filling with text until it overflows to next line.}
    \label{Source with cite2.}
\end{figure}

\end{document}

在此处输入图片描述

相关内容