2

I'm writing a document with many tables and figures.

This is a reproducible piece of my document. (With LuaTeX, but plain LaTeX is OK too).

\RequirePackage{luatex85}
\documentclass[11pt,a4paper]{article}
\usepackage[capitalise,noabbrev]{cleveref}
\usepackage[demo]{graphicx} 
\usepackage{float}
\usepackage[section]{placeins}
%\counterwithin{figure}{subsection}
\usepackage[skip=5pt]{caption}  %, margin=2em   ,labelfont=it,  , textfont=it
\captionsetup{font=small, labelfont=bf} %,format=hang
\addtolength{\footnotesep}{5mm}

\begin{document}

\section{Introduction}
\cref{fig:esquema1} summarizes the process

\begin{figure}[h]
    \centering
    \includegraphics[width=0.95\linewidth]{esquema1}
    \caption{My caption.}
    \label{fig:esquema1}
\end{figure}

\end{document}

I'd like that some captions instead of "Figure 1" were automatically called "Diagram 1", both below the figure and when referenced from the document.

How can tell LaTeX to do it?

I've read something like

%\captionsetup[figure]{name={Fig.}}   

will change the name, but it will do it for all Figures.

I would like to keep that name for figures (real pictures) but add a new "Diagram" name for other (diagrams made with tikz and other).

  • Please fix your document by adding graphicx and cleveref package loading, graphicx with demo option, otherwise reproducible is doubtful ;-) – user31729 Nov 15 '17 at 20:47
  • float includes \newfloat command to declare new floats, why not use it to distinguish figures from diagram? – Ignasi Nov 15 '17 at 21:01
  • @Ignasi Could you post an example and explain the advantages of "\newfloat" over Christian's methods, please? – skan Nov 16 '17 at 10:54
  • @skan If you just want to use diagram occasionally, Chirstian's method is the easiest. I've tested with newfloat and table of figures doesn't look good. – Ignasi Nov 16 '17 at 11:26
  • @Ignasi: The idea with newfloat is good, in my point of view, but it will introduce a new \listof... macro (as far as I know), so diagram and figure are not merged in LoF. Perhaps \let\l@diagram\l@figure will improve the look of LoF which look bad as you reported? – user31729 Nov 16 '17 at 11:38
1

Here is a version suitable for some few occurences of such diagram caption:

  1. Define a counter named diagram (for example) that shares the same value as figure, with \newaliascnt from aliascnt package.
  2. Say \captionsetup{name={Diag.}} within the figure environment that should have Diag. as caption lead-in.
  3. Define \crefname and \Crefname for diagram counter.
  4. Say \label[diagram]{...} in order to make cleveref aware that the diagram counter should be referenced and not figure.

\RequirePackage{luatex85}
\documentclass[11pt,a4paper]{article}
\usepackage{float}
\usepackage[section]{placeins}
\usepackage{aliascnt}
\newaliascnt{diagram}{figure}

%\counterwithin{figure}{subsection}
\usepackage[skip=5pt]{caption}  %, margin=2em   ,labelfont=it,  , textfont=it
\captionsetup{font=small, labelfont=bf} %,format=hang
\addtolength{\footnotesep}{5mm}

\usepackage[demo]{graphicx}
\usepackage{cleveref}

\crefname{diagram}{diagram}{diagrams}
\Crefname{diagram}{Diagram}{Diagrams}

\begin{document}

\section{Introduction}
\cref{fig:esquema1} summarizes the process

\begin{figure}[h]
    \captionsetup{name={Diag.}} 
    \centering
    \includegraphics[width=0.95\linewidth]{esquema1}
    \caption{My caption.}
    \label[diagram]{fig:esquema1}
\end{figure}

\end{document}
  • What if I want to share the same counter for diagrams and figures or us different ones? – skan Nov 16 '17 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.