Graphics, Figures & TablesNAG warning: What is wrong with a label in this simple code?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

NAG warning: What is wrong with a label in this simple code?

Post by Cham »

I'm getting a very mysterious NAG warning with the following code, and I don't understand what is going on here.

Code: Select all

\RequirePackage[l2tabu,orthodox]{nag}
\documentclass[11pt,twoside]{book}
\usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
\usepackage{graphicx}
\usepackage{float}

\begin{document}

	\begin{figure}[H]
		\includegraphics{example-image-a}
	\end{figure}

\subsubsection{Title}\label{label} %<--- What the Hell?

Test

\end{document}
Here's the NAG warning:
Package nag Warning: \label in float, but not after \caption on input line 13.
So what is wrong with the line shown in the code above?

The trouble appears to be related with the picture.

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

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

NAG warning: What is wrong with a label in this simple code?

Post by Johannes_B »

With H you disallow automatic placement, so why use a figure environment at all? Even more, since no caption is inside.

Look at the bold text on page 3 of the nag documentation.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

NAG warning: What is wrong with a label in this simple code?

Post by Cham »

I never want automatic placement of figures. I want them exactly there, where I need them to be.

And most of my figures do have a caption and a label. This code (as always) is just a MWE to show the issue.

Is this related to the NAG issue ? I don't remember having this issue before with the NAG package.

EDIT: I'm having a few figures without a caption, and this may be the cause of the issue. Would adding a blank caption like \caption*{} be a solution? It would add an empty line below the figures and this may cause some spacing problem.

What would be your suggestion, for the few figures without any caption?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

NAG warning: What is wrong with a label in this simple code?

Post by Johannes_B »

It is pointless to use a floating environment just to prevent prevent the floating.

Use \captionof{type}{caption title} instead. I know you are using the caption package anyway.

For Figueres without a caption, using a floating environment is even more pointless.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

NAG warning: What is wrong with a label in this simple code?

Post by Cham »

I don't understand what you're saying. I'm using the figure environment, since it's a figure!

What is the "type" in \captionof{type}{caption title} ? How do I use this command?
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

NAG warning: What is wrong with a label in this simple code?

Post by Cham »

So what would be a good solution to put a centered non-floating figure, without any caption, to remove the pesky nag warnings?

To me, a figure is a figure so I should use the figure environment, even if it has no caption. It's also giving me the possibility to copy/paste the same code in another document and add a caption if needed.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

NAG warning: What is wrong with a label in this simple code?

Post by Johannes_B »

Code: Select all

\RequirePackage[l2tabu,orthodox]{nag}
    \documentclass[11pt,twoside]{book}
    \usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
    \usepackage{graphicx}
    \usepackage{caption}
     
\setcounter{secnumdepth}{5}
    \begin{document}
     
    	\begin{figure}
		This text could be a table, LaTeX doesn't care. It is just about the counter.
    	\end{figure}
    	\begin{center}
    		\includegraphics{example-image-a}
    		%\captionof{figure}{This shows an example image}
    	\end{center}
     
    \subsubsection{Title}\label{label} %<--- What the Hell?
     
    Test\ref{label}
     
    \end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

NAG warning: What is wrong with a label in this simple code?

Post by Cham »

Ok, I adopt your suggestion. Thanks.
Post Reply