## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ NAG warning: What is wrong with a label in this simple code? Topic is solved

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

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

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

\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.

Johannes_B
Site Moderator
Posts: 3953
Joined: Thu Nov 01, 2012 4:08 pm
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.

Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm
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?

Johannes_B
Site Moderator
Posts: 3953
Joined: Thu Nov 01, 2012 4:08 pm
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.

Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm
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?

Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm
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.

Johannes_B
Site Moderator
Posts: 3953
Joined: Thu Nov 01, 2012 4:08 pm
\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.

Cham
Posts: 894
Joined: Sat Apr 02, 2011 4:06 pm