0

Running the following code in Kile, I obtain a caption position of the first image that is different from the second one since the text inserted in the second picture is less than the first one. This is unaesthetic.

\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}

This is what I mean:

enter image description here

How can I fix this problem in a way that, for example, captions are all in the same position that is, in this case, the position of the first image ? So they are all starting on the "extreme left position" whatever is the length of text to be inserted in ?

2
  • @Marijn it could, however the Simon Dispa answer is more straightforward in my case. Commented Nov 27, 2022 at 15:45
  • I understand the answer by Simon is more directly applicable to your specific situation, however for the organization of the site as a whole I think it's a good idea to close this question as a duplicate.
    – Marijn
    Commented Nov 27, 2022 at 15:50

2 Answers 2

1

By loading the package caption it is possible to configure the format of all document captions. For example

\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}

The standard LATEX document classes (article, report, and book) automatically center a caption if it fits in one single line.

singlelinecheck=false switches this extra centering off.

a

1

This uses a minipage to match both the left and right edges of the caption to the image.

\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}

Not the answer you're looking for? Browse other questions tagged .