2


I am preparing a document of class article in LaTex. I am required to include the figure captions, but provide the figures themselves as separate image files without incorporating them into the document. Therefore, I would like to create a section in my file containing all the figure captions, but format them basically like the rest of the "normal" text in the document. I believe someone asked a similar question before, but wanted to create a list of figures to basically the same end by only printing the long title. However, I would like to know whether this is also possible by modifying e.g. the \vspace parameter.
So far, I have used the following code for each of my figures:

\documentclass[12pt,a4paper]{article}
\usepackage[a4paper,left=2.6cm, right=2.9cm, top=3.5cm, bottom=3.5cm]{geometry}
\renewcommand{\baselinestretch}{2}
\usepackage{lineno}
\usepackage{caption}
\captionsetup{justification=raggedright,singlelinecheck=false}

\begin{document} \linenumbers \section{Some section} Some text

\section{Figure legends} \begin{figure}[!h] \internallinenumbers \caption{This is my caption.} \label{fig:myfig} \vspace{-1.2cm} \end{figure}

\begin{figure}[!h] \internallinenumbers \caption{This is my other caption.} \label{fig:myfig1} \vspace{-1.2cm} \end{figure} \clearpage \end{document}

This gives an output that is somewhat similar to what I need. However, I have the problem my last caption does not fit on the same page as the others and is therefore positioned in the middle of the following page. I have tried replacing \begin{figure}[!h] with \begin{figure}[!t], but this does not yield the output I need. Instead I would like the caption to start in the first line of the new page. Also, I wonder whether there is a way to set the spacing between the different captions to equal that of lines in the rest of the text.

Mareike
  • 105
  • The question is what is the purpose of separate image files? They may intend simply to move all the images to a few pages to reduce the use of color print. In that case they may want your captions bundled with the images. Of course you would still need phantom captions for \label and \ref (\refstepcounter{figure}} – John Kormylo Aug 09 '23 at 15:01
  • I would suspect typesetting is easier if you have good quality images as separate files. – Mareike Aug 14 '23 at 08:37
  • PDFs retain the full resolution of the original image. (This can make for rather large file sizes with high res jpegs.) Of course, if you don't have the right software (Acrobat) you may need separate image files. – John Kormylo Aug 14 '23 at 12:53
  • Then again, maybe they want to reduce the resolution firrst. – John Kormylo Aug 14 '23 at 13:01

2 Answers2

2

Given your requirements, it sounds like you don't need the figure environment at all. The figure environment is a floating environment, which means LaTeX can move it around to fit the overall layout of the page, and this is why you're seeing the unexpected positioning.

Since you're not including any images, you can just use the \captionof command from the caption package to create captions outside a figure environment. This will treat the caption like normal text.

Here is your adjusted code:

\documentclass[12pt,a4paper]{article}
\usepackage[a4paper,left=2.6cm, right=2.9cm, top=3.5cm, bottom=3.5cm]{geometry}
\renewcommand{\baselinestretch}{2}
\usepackage{lineno}
\usepackage{caption}
\captionsetup{justification=raggedright,singlelinecheck=false}

\begin{document} \linenumbers \section{Some section} Some text

\section{Figure legends}

\internallinenumbers \captionof{figure}{This is my caption.} \label{fig:myfig}

\internallinenumbers \captionof{figure}{This is my other caption.} \label{fig:myfig1}

\clearpage \end{document}

The \captionof command takes two arguments: the first is the type of caption (in this case, 'figure'), and the second is the actual caption text. This command will make the caption look like normal text and will not cause any unusual space before or after it.

  • I think \captionof is quite elegant and gives what I was looking for. However, invoking \internallinenumbers in this case does not give good results in terms of line numbering as (in my case) only the last line of each caption is numbered. Yet, this is a separate problem from what I initially stated. I will try to find a solution. – Mareike Aug 14 '23 at 08:45
2

This creates a file of "normal" captions, one per page, no margins. You could add the images here as well. But since this is a separate file, \label will do no good. I got \textwidth from your document.

Not sure what the line numbering was about, unless the captions count against the total number of lines (as opposed to being part of the image).

\documentclass[multi={figure}]{standalone}
\usepackage{graphicx}
\usepackage{caption}
\captionsetup{justification=raggedright,singlelinecheck=false, position=below}

\makeatletter \renewenvironment{figure}{\def@captype{figure}\minipage{441.01773pt}}{\endminipage} \makeatother

\begin{document} \begin{figure} \caption{This is my caption.} \end{figure}

\begin{figure} \caption{This is my other caption.} \end{figure} \end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120