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

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

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

Postby Cham » Tue Aug 07, 2018 11:05 pm

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

  1. \RequirePackage[l2tabu,orthodox]{nag}
  2. \documentclass[11pt,twoside]{book}
  3. \usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
  4. \usepackage{graphicx}
  5. \usepackage{float}
  6.  
  7. \begin{document}
  8.  
  9. \begin{figure}[H]
  10. \includegraphics{example-image-a}
  11. \end{figure}
  12.  
  13. \subsubsection{Title}\label{label} %<--- What the Hell?
  14.  
  15. Test
  16.  
  17. \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.

User avatar
Johannes_B
Site Moderator
Posts: 3803
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Wed Aug 08, 2018 7:05 am

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

Postby Cham » Wed Aug 08, 2018 2:13 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?

User avatar
Johannes_B
Site Moderator
Posts: 3803
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Wed Aug 08, 2018 3:03 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.

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

Postby Cham » Wed Aug 08, 2018 3:51 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?

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

Postby Cham » Wed Aug 08, 2018 4:58 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.

User avatar
Johannes_B
Site Moderator
Posts: 3803
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Wed Aug 08, 2018 6:18 pm

  1. \RequirePackage[l2tabu,orthodox]{nag}
  2. \documentclass[11pt,twoside]{book}
  3. \usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
  4. \usepackage{graphicx}
  5. \usepackage{caption}
  6.  
  7. \setcounter{secnumdepth}{5}
  8. \begin{document}
  9.  
  10. \begin{figure}
  11. This text could be a table, LaTeX doesn't care. It is just about the counter.
  12. \end{figure}
  13. \begin{center}
  14. \includegraphics{example-image-a}
  15. %\captionof{figure}{This shows an example image}
  16. \end{center}
  17.  
  18. \subsubsection{Title}\label{label} %<--- What the Hell?
  19.  
  20. Test\ref{label}
  21.  
  22. \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: 894
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Wed Aug 08, 2018 6:55 pm

Ok, I adopt your suggestion. Thanks.


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 13 guests