Graphics, Figures & Tablesfigure caption with only the number

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
christina_t
Posts: 27
Joined: Tue Sep 16, 2008 1:16 am

figure caption with only the number

Post by christina_t »

Hi all,

I have a file with 600 images, divided in chapters, and I would like to be able for one chapter (below 'catalog') to only put the number of the figure in the caption, with the description being in the list of figures. I don't want 'Fig. 1', only '1'. However, I would like this to be applied only for one chapter, and not in all of the chapters. Is that possible?

Code: Select all

\documentclass[11pt,a4paper,twoside]{report}

\usepackage{setspace}

\usepackage[dvipdfm]{graphicx}
\usepackage{graphicx}
\usepackage{color}
\usepackage{epsf}
\usepackage{supertabular}
\usepackage{picins}
\usepackage{longtable}
\usepackage{semtrans}
\usepackage{fancyhdr}
\usepackage{natbib}
\usepackage{threeparttable}
\usepackage{tabularx}
\usepackage{synttree}
\usepackage{multirow}
\usepackage{amsfonts}
\usepackage{rotating}
\usepackage{lscape}
\usepackage{hvfloat}
\usepackage{sidecap}
\usepackage{float}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary[trees]
\setlength{\baselineskip}{13pt}
\usepackage[top=18mm, bottom=18mm, left=15mm, right=15mm]{geometry} 
\pagestyle{fancy}
\usepackage{lipsum}
\usepackage{hyperref}


\begin{document}

\tableofcontents
\newpage
\listoffigures
\newpage
\listoftables

\chapter{Introduction}
\pagenumbering{arabic}
\fancyhead[CE]{\leftmark}
\fancyhead[CO]{\rightmark}
\fancyfoot[C]{\thepage}
\input{intro}


\chapter[Catalog]{Catalog}
\fancyhead[LE]{The catalogue}
\fancyhead[RO]{}
\fancyfoot[C]{\thepage}
\input{catalogue1}


\end{document}


and an example from the catalog file regarding a figure

Code: Select all

\begin{minipage}{5cm}
\includegraphics[scale=0.55]{pic1}
\caption[Drawing of blah]{}
\end{minipage}
but this gives me 'Fig.1:', while I would only want '1'

Many thanks in advance
Christina
Last edited by Stefan Kottwitz on Fri Nov 09, 2012 2:01 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

figure caption with only the number

Post by cgnieder »

You can use the caption package to define a caption setup for this, see the caption manual section 4 (Own Enhancements).

In the example below I used \captionof since \caption won't work in a {minipage} alone.

Code: Select all

\documentclass{article}
\usepackage{graphicx}

\usepackage{caption}
\DeclareCaptionFormat{empty}{#1}
\renewcommand*\figurename{Fig.}

\usepackage{mwe}% for the example image

\begin{document}
\listoffigures

\section{Bla}
\captionsetup{format=empty}
\begin{minipage}{5cm}
 \includegraphics[width=5cm]{example-image-a}
 \captionof{figure}{Drawing of blah}
\end{minipage}
\begin{minipage}{5cm}
 \includegraphics[width=5cm]{example-image-b}
 \captionof{figure}{Drawing of blub}
\end{minipage}

\end{document}
captionformat.png
captionformat.png (11.18 KiB) Viewed 12876 times
BTW: you load graphicx twice in your preamble. Also, you shouldn't specify the driver for it unless necessary.

Regards
site moderator & package author
christina_t
Posts: 27
Joined: Tue Sep 16, 2008 1:16 am

figure caption with only the number

Post by christina_t »

Hi and many thanks for the reply. Is there a way to drop the 'fig.' completely and just get its number? I also do not want this for all my 'chapters' but only for one, as there are also pictures in the other chapters. I managed to drop the 'fig.' by putting

Code: Select all

\renewcommand{\figurename}{}
\chapter[Catalog]{Catalog}
\fancyhead[LE]{The catalogue}
\fancyhead[RO]{}
\fancyfoot[C]{\thepage}
\input{catalogue1}
just before I enter the chapter, but this gives me "4.1:" for chapter 4 pic 1. I would now like to drop the colon... This I have done without using the caption package, because it seems too complicated to change all captions now with \captionof{figure}{blah}, and for some pictures I want a different caption appearing in the text and another in the list of images.

Many thanks again!
Last edited by cgnieder on Thu Nov 15, 2012 11:44 pm, edited 1 time in total.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

figure caption with only the number

Post by cgnieder »

Several things:
  • the reason I proposed the caption package was not for the usage of \captionof. The reason was to use it to define a new caption format. I silently assumed you knew that \caption is only allowed in floating environments such as {figure} and {table} and thought you'd see that I didn't use them in my MWE (Infominimal working example) and hence needed \captionof there. My proposal also works with \caption!
  • I get the feeling you didn't read the caption manual that I linked. You could have read this section there:
    You can define your own caption formats using the command

    Code: Select all

    \DeclareCaptionFormat{ name }{ code using #1, #2 and #3 }
    At usage the system replaces #1 with the caption label, #2 with the separator and #3 with the text.
    So the standard format plain is pre-defined by the caption package as

    Code: Select all

    \DeclareCaptionFormat{plain}{#1#2#3\par}
  • One can invoke \captionsetup{} several times which means one can use one format for one part of the document and other formats for the rest quite easily. Below is an example again, this time without a picture. Please take the time copying it as a test document, compile it, and see what which part of the code does.

Code: Select all

\documentclass{article}
\usepackage{graphicx}

\usepackage{caption}
\DeclareCaptionFormat{empty}{}% a completely invisible caption

\usepackage{mwe}% for the example image

\begin{document}
\listoffigures

\section{Foo}
\captionsetup{format=empty}
\begin{figure}[ht]
 \centering
 \includegraphics[width=5cm]{example-image-a}
 \caption{Drawing of foo}
\end{figure}

\begin{figure}[ht]
 \centering
 \includegraphics[width=5cm]{example-image-b}
 \caption{Drawing of bar}
\end{figure}

\section{Bar}
\captionsetup{format=plain}% reset to the standard caption format again
\begin{figure}[ht]
 \centering
 \includegraphics[width=5cm]{example-image-a}
 \caption{Drawing of foobar}
\end{figure}

\begin{figure}[ht]
 \centering
 \includegraphics[width=5cm]{example-image-b}
 \caption{Drawing of baz}
\end{figure}

\end{document}
site moderator & package author
christina_t
Posts: 27
Joined: Tue Sep 16, 2008 1:16 am

figure caption with only the number

Post by christina_t »

Hi Clemens and thanks again for your reply. I managed to do what I wanted with the caption package at last, but I do need to use \captionof since all my figures are in minipage environment. Thanks! In the end I used

Code: Select all

\usepackage{caption}
\DeclareCaptionFormat{empty}{#1}
\renewcommand*\figurename{}

to get what I wanted. Again many thanks!

Christina
Post Reply