在 Kile 中运行以下代码,我获得的第一张图片的标题位置与第二张图片的标题位置不同,因为第二张图片中插入的文本少于第一张图片。这很不美观。
\begin{figure}[!ht]
\includegraphics[scale=0.80]{examplesignalchangesfrequency.png}
\caption{Example of time domain oscillating signal which contains four frequencies at four different times.}
\label{exampletimedomainsignal}
\end{figure}
Fig. \ref{exampleFFTtimedomainsignal} is the corresponding frequency spectrum.
\begin{figure}[!ht]
\includegraphics[scale=0.80]{exampleFFTsignalchangesfrequency.png}
\caption{Example of FFT applied to the signal in figure \ref{exampletimedomainsignal}.}
\label{exampleFFTtimedomainsignal}
\end{figure}
我的意思是:
我该如何解决这个问题,例如,标题都位于同一位置,即本例中第一张图片的位置?所以无论要插入的文本长度是多少,它们都从“最左边的位置”开始?
答案1
通过加载包,caption
可以配置所有文档标题的格式。例如
\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{caption} % added <<<<<<<
\captionsetup[figure]{hangindent=0pt, singlelinecheck=false}% added <<<<<<<
\begin{document}
\begin{figure}[!ht]
\includegraphics[scale=0.80]{example-image-a}
\caption{Example of time domain oscillating signal which contains four frequencies at four different times.}
\label{exampletimedomainsignal}
\end{figure}
Fig. \ref{exampleFFTtimedomainsignal} is the corresponding frequency spectrum.
\begin{figure}[!ht]
\includegraphics[scale=0.80]{example-image-b}
\caption{Example of FFT applied to the signal in figure~\ref{exampletimedomainsignal}.}
\label{exampleFFTtimedomainsignal}
\end{figure}
\end{document}
如果标题适合一行,标准 LATEX 文档类(文章、报告和书籍)会自动将标题居中。
singlelinecheck=false
关闭这个额外的居中功能。
答案2
这使用小页面将标题的左右边缘与图像进行匹配。
\documentclass{article}
\usepackage{pgfplots}
\usepackage{showframe}% alignment tool
\begin{document}
\begin{figure}[!ht]
\sbox0{\includegraphics[scale=0.80]{example-image}}% measure width
\centering
\begin{minipage}{\wd0}
\usebox0
\caption{Example of time domain oscillating signal which contains four frequencies at four different times.}
\label{exampletimedomainsignal}
\end{minipage}
\end{figure}
\end{document}