Graphics, Figures & TablesCaption including a full stop

Information and discussion about graphics, figures & tables in LaTeX documents.
magical marshmallow
Posts: 30
Joined: Mon Jan 21, 2013 11:37 am

Caption including a full stop

Post by magical marshmallow »

Hi,

Just wondering has anyone come up with this problem

I have many images and tables in a report. When the caption is displayed, it reads

Figure X.X.: Caption text

The fullstop (.) is undesired, but I cannot figure out how to get rid of it.

My images are included using

Code: Select all

	\begin{figure}[!ht]
	\centering
	\includegraphics[width=\linewidth]{image.png}
	\caption[Caption for TOC]{Caption text}
	\label{fig:Label text}
	\end{figure}
and a similar setup for tables

Code: Select all


\begin{table}[!ht]
  \centering
	\caption[Caption for TOC]{Caption for text}
	\vspace{0.5cm}
\label{tab:Table label}
    \begin{tabular}{lr}
    \toprule
Table & text\\
    \bottomrule
    \end{tabular}
 \end{table}
However I have some code to label equations This code however when used does not produce the undesired . in the text

Code: Select all

\usepackage{amsmaths}
\usepackage{aliascnt}
\newaliascnt{eqnfloat}{equation}
\newfloat{eqnfloat}{h}{eqflts}
\floatname{eqnfloat}{Equation}

\newcommand*{\ORGeqnfloat}{}
\let\ORGeqnfloat\eqnfloat
\def\eqnfloat{%
  \let\ORIGINALcaption\caption
  \def\caption{%
    \addtocounter{equation}{-1}%
    \ORIGINALcaption
  }%
  \ORGeqnfloat
}
\begin{document}

	\begin{eqnfloat}[!htbp]
	\begin{equation}
Eqiation
	\end{equation} 

	\label{eq:Equation label}
	\caption{Caption text}
	\end{eqnfloat}
\end{document}
Anybody got any ideas?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Caption including a full stop

Post by localghost »

An adequate problem description consists of a self-contained and minimal example that clearly reproduces the undesired behaviour and not of loosely code snippets. It is appreciated very much if you keep that in mind for future questions and only post examples which you have checked for functionality and which make a problem comprehensible for others.


Thorsten
magical marshmallow
Posts: 30
Joined: Mon Jan 21, 2013 11:37 am

Caption including a full stop

Post by magical marshmallow »

Apologies.

I've managed to narrow this problem down to the appendices section of my report and within that, the particular \chapter at the start of it. When I removed this, all is well with the caption formatting, but when it is present, I get the extra period in my figure and table captions.

Code: Select all

\documentclass{scrreprt}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{appendix}

\begin{document}
  \begin{figure}
    \centering
    \includegraphics[scale=1]{image.png}
    \caption[Description for LOF]{Description of image}
  \end{figure}
        
  \begin{appendices}
    \chapter{Chapter 1}
  \end{appendices}
\end{document}
Anyone have any ideas?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Caption including a full stop

Post by localghost »

Set the option numbers=noenddot for the document class. Other possible settings for this option can be found in Table 3.14 of the KOMA-Script user guide (English version). Reasons for this behaviour can be found in Sections 3.16 and 3.22 of the same document.
Klausiber
Posts: 16
Joined: Sun Apr 14, 2013 11:41 pm

Caption including a full stop

Post by Klausiber »

As my question is closely related - the major difference being that I do want the trailing period - I hope it's ok to use this thread instead of starting a new one.
localghost wrote:Set the option numbers=noenddot for the document class. Other possible settings for this option can be found in Table 3.14 of the KOMA-Script user guide (English version).
This option will (unfortunately) not work for custom floats created with "newfloat" (see also http://latex-community.org/forum/viewto ... 45&t=23028). These floats will never add a period after the reference number. I did not find any hints in the documentation of newfloat or caption on how to change this.

Is there any way to
  1. apply the KOMA setting to these floats as well?
  2. add the trailing period to custom floats "manually"?
Here's a MWE:

Code: Select all

\documentclass[english,numbers=enddot] {scrbook}
\usepackage[T1]{fontenc}

\usepackage{listings}
\lstset{frame=single,aboveskip=0pt,belowskip=0pt}

\usepackage{caption,newfloat}
\DeclareFloatingEnvironment[
  fileext=lol,
  name=Listing
]{listing}


\begin{document}
\chapter{foo}
\begin{figure}[!h]
  \centering
  \rule{\textwidth}{7mm}
  \caption{Figure}
\end{figure}

\begin{listing}[!h]
  \begin{lstlisting}[gobble=4]
    Some code
  \end{lstlisting}
  \caption{Listing}
\end{listing}

\end{document}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Caption including a full stop

Post by localghost »

Klausiber wrote:[…] This option will (unfortunately) not work for custom floats created with "newfloat" (see also http://latex-community.org/forum/viewto ... 45&t=23028). These floats will never add a period after the reference number. I did not find any hints in the documentation of newfloat or caption on how to change this.

Is there any way to
  1. apply the KOMA setting to these floats as well?
  2. add the trailing period to custom floats "manually"?
[…]
For a class of KOMA-Script you may use the built-in mechanism by the \DeclareNewTOC command for the new float environment and try to create and customize the corresponding sub-floats by subcaption from the caption bundle. I'm not sure if subcaption detects new floats generated this way and automatically creates the corresponding sub-floats as it does for floats created by newfloat. The \DeclareNewTOC macro is provided by the »tocbasic« package. The package is described in Chapter 13 of the KOMA-Script manual. The macro itself is explained in detail in Section 13.5 of that document.
Klausiber
Posts: 16
Joined: Sun Apr 14, 2013 11:41 pm

Caption including a full stop

Post by Klausiber »

localghost wrote: For a class of KOMA-Script you may use the built-in mechanism by the \DeclareNewTOC command for the new float environment
Thanks for your help! This works pretty well, except for two problem: A minor issue is that I need to use the listname option because otherwise the environment name is set all in caps. According to the documentation only the first letter should be capitalised.

The real problem is that adding the counterwithin option breaks the "List of Listings". As the following example shows there is no space after the reference number. (Please note, that I also commented the listname option to demonstrate the wrong capitalisation.)

Code: Select all

\documentclass[numbers=enddot] {scrbook}
\usepackage[T1]{fontenc}

\usepackage{listings,caption,tocbasic}
\lstset{frame=single,aboveskip=0pt,belowskip=0pt}

\DeclareNewTOC[
  counterwithin=chapter,
  type=listing,
  float,
  floattype=4,
%  listname={List of Listings},
]{lool}


\begin{document}
\listoffigures
\listoflistings

\chapter{foo}
\begin{figure}[!h]
  \centering
  \rule{\textwidth}{7mm}
  \caption{Figure}
\end{figure}

\begin{listing}[!h]
  \begin{lstlisting}[gobble=4]
    Some code
  \end{lstlisting}
  \caption{Listing}
\end{listing}

\end{document}
Am I missing something or is this a bug in KOMA-script?
localghost wrote:I'm not sure if subcaption detects new floats generated this way
It does not, but that's only one additional line.
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Caption including a full stop

Post by sommerfee »

Klausiber wrote:apply the KOMA setting to these floats as well?

Code: Select all

\makeatletter
\renewcommand\fnum@listing{\listingname~\thelisting\autodot}
\makeatother
However, I think this should be done automatically by the newfloat package. Will change that ASAP.
add the trailing period to custom floats "manually"?

Code: Select all

\DeclareCaptionLabelFormat{autodot}{#1~#2\autodot}
\captionsetup[listing]{labelformat=autodot}
(This one will add the "autodot" feature to the listing environment.)
or

Code: Select all

\DeclareCaptionLabelFormat{period}{#1~#2.}
\captionsetup{labelformat=period}
(This one will add the dot to all floating environments.)
Klausiber
Posts: 16
Joined: Sun Apr 14, 2013 11:41 pm

Caption including a full stop

Post by Klausiber »

sommerfee wrote:

Code: Select all

\DeclareCaptionLabelFormat{autodot}{#1~#2\autodot}
\captionsetup[listing]{labelformat=autodot}
(This one will add the "autodot" feature to the listing environment.)
or

Code: Select all

\DeclareCaptionLabelFormat{period}{#1~#2.}
\captionsetup{labelformat=period}
(This one will add the dot to all floating environments.)
Absolutely perfect. Thanks a lot! :-)

YFTR: I did read the documentation of labelformat but failed to realise that DeclareCaptionLabelFormat was the missing link to my problem.
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Caption including a full stop

Post by sommerfee »

Klausiber wrote:A minor issue is that I need to use the listname option because otherwise the environment name is set all in caps. According to the documentation only the first letter should be capitalised.
This seems to be a bug for me, did you already report it to Markus Kohm, the author and maintainer of KOMA-Script?
The real problem is that adding the counterwithin option breaks the "List of Listings". As the following example shows there is no space after the reference number.
This seems to be a bug, too. When replacing \DeclareNewTOC[...]{lool} with

Code: Select all

\DeclareFloatingEnvironment{listing}
% Workaround for missing autodot feature of \DeclareFloatingEnvironment
\DeclareCaptionLabelFormat{autodot}{#1~#2\autodot}
\captionsetup{labelformat=autodot}
the spacing after the reference number seems to be fine, although \DeclareFloatingEnvironment is using tocbasic internally (when using a KOMA-Script document class, like in this case), too.

BTW: https://sourceforge.net/p/latex-caption/tickets/14/ , I will see if I can get this fixed the upcoming week-end.
Post Reply