Graphics, Figures & TablesNumbering figures in LyX fails (figures have same numbers)

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
SteveF
Posts: 3
Joined: Sat Feb 21, 2015 4:13 pm

Numbering figures in LyX fails (figures have same numbers)

Post by SteveF »

Hi, I'm a new LyX user without knowledge of LateX. Who can help me to solve this problem : I activated AMS for numbering sections, subsections etcetera... But when I lable a figure with insert label, then "fig:....." , then all figures within the same subsection are numbered with the same number : the number of the subsection. How do I solve this problem ?

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

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Numbering figures in LyX fails (figures have same numbers)

Post by rais »

SteveF wrote:But when I lable a figure with insert label, then "fig:....." , then all figures within the same subsection are numbered with the same number : the number of the subsection. How do I solve this problem ?
looks like you're using \label before \caption (or no \caption at all). Reverse the order: first \caption, then \label.

Not sure how that translates to LyX.

KR
Rainer
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Re: Numbering figures in LyX fails (figures have same number

Post by Stefan Kottwitz »

Hi Steve,

welcome to the forum!

Perhaps post a reduced copy of the LyX file here, as attachment to a post. Or the LaTeX export.

Stefan
LaTeX.org admin
SteveF
Posts: 3
Joined: Sat Feb 21, 2015 4:13 pm

Re: Numbering figures in LyX fails (figures have same number

Post by SteveF »

Hi Stefan, I do not know how to sent a reduced part of the Lyx file, because it is a "what you see is what you get" latex editor. I do not want figure everywhere where I do not want them. That was the reason I used insert > box > simple frame and then insert > Graphics and then insert > label fig:blabla.. and within the box Figure : (control L) \ref{fig:blabla..} to show the number of the picture. The insert > floats > figure or figure wrap float do not place the figures where I want them. Now I tried again : insert > floats > figure wrap float. Then insert graphics. In Document > settings > float placement > advanced placement options > here definitely. That does not work at all ! The figure is everywhere not on the place I wanted. Directly below that float, I have a box > simple frame, with a picture inside. And the picture from the figure wrap float is printed through the other picture in de box simple frame. But not above it. The text below the box is on the left of the paper and the right side is empty. That was the reason I do not trust the floats and why I use insert > box > simple frame then insert graphics and insert label. Box is always placed on the right place. But the problem is the numbering of the pictures. Every picture in the subsection (for example 0.1.3) gets the same number (0.1.3). Every label has a different name. But they get the same number automatically, that can be seen in the PDF. So the problem with insert > float > .... even with advanced placement options > here definitely.... do not place pictures on a free place on the page. And not where I wanted them to place.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Numbering figures in LyX fails (figures have same numbers)

Post by Stefan Kottwitz »

A label needs an anchor for the reference, which is implicitly set. In case of figures, the anchor is implicitly set by the caption. So, you need to have a caption before you set the label, in this order. This is, what Johannes said.

You are writing a scientific document, as I understand. And it seems to be a big one, as you have subsections. So, think again about the whole concept of figures, numbering, and cross-referencing.

You number figures not to count them, but to refer to their number by a cross-reference. That's common in large scientific documents, because figures are moving to the optimal place. This is often the top of the page. And the writing software does it automatically for optimal page breaks. If it doesn't fit to the page, following text comes first and the figure goes to the top of the next page. While a 300 pages document grows, text is inserted here and there, and page breaking and figures would automatically be adjusted.

That's what Word users often don't know at all, and that's very often new to LaTeX users. I suggest, use floats, and let LaTeX do the placement. Otherwise inserting text would mean adjusting figure position or page break, depending on the changing space on the page. And, if you place a figure right at the page where you talk about it, you don't need reference or number.

For easier placement, so the figure won't move much, choose all existing options for LyX' figure placement, which mean "here", "top", "bottom", "page", possibly there's also a "relaxed" option. The corresponding maximum set of LaTeX options is [htbp!].

Stefan
LaTeX.org admin
SteveF
Posts: 3
Joined: Sat Feb 21, 2015 4:13 pm

Re: Numbering figures in LyX fails (figures have same number

Post by SteveF »

Thanx a lot Stefan. I discovered that in the float itself (using the right mouse button) I can choose to place the figure at that place exactly, or place there only if possible, or let LaTeX choose a place, as you said. Indeed a scientific text, the first time for me writing a thesis, and also the first time not using Open Office. About Caption first then label , I have to study what caption is and does, how LaTeX works, but later after I finish my thesis (within a week). Thanx both of you for helping me. It is working. And I am happy !
Post Reply