我有一個相當令人討厭的論文指南需要遵循,不幸的是我無法用我的 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
這是所需的輸出:
答案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}