Captions with Chapter Number

Everything related to our flagship word processor.
Post Reply
schac
Posts: 4
Joined: 2015-03-03 03:06:39

Captions with Chapter Number

Post by schac »

Hi
For a paper I am required to include the chapter number in the caption of figures. Ex: "Figure 4-1". 4 refers to chapter four and 1 to the first figure in this chapter. Word can automate the numbering but I could not figure out a way of doing it in NWP. Unfortunately, the manual does not explain the functionality of several buttons in the list sidebar, so any help would be highly appreciated.
Thank you!
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Captions with Chapter Number

Post by phspaelti »

Hello shac,
One thing that Nisus cannot do unfortunately is use one list series to reset another. So if you were hoping to reset the Figure numbering automatically from the chapter number, that can't be done. There are some other tricks that one can use to approximate the kind of numbering you are looking for. One idea is to have the figure numbering with a Level 1 that does not show a number, and use the Level 2 for the figure captions. You will then have to insert a Figure number 'reset' at the beginning of every chapter. This paragraph could be made very small (and inserted using the 'Next Style' feature) right after each Chapter heading. I am attaching a sample file that demonstrates this.
Figure Caption numbering with Chapters.rtf
(24.42 KiB) Downloaded 353 times
[Note: A shortcoming in the original file was discovered. The file has been replaced with an updated version (March 6)]

Another approach might be to use bookmarks and/or macros, but this will only be semi-automatic. (One could write a macro that just cleans up all such cases at the end, for example). However this would have the advantage of being more flexible than auto-numbers.
Last edited by phspaelti on 2015-03-05 22:08:56, edited 2 times in total.
philip
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Captions with Chapter Number

Post by Þorvarður »

schac wrote:"Figure 4-1". 4 refers to chapter four and 1 to the first figure in this chapter
Hi schac,

You can do this in Nisus if you insert a Section Break after each chapter, so that each chapter corresponds to one section. Then section numbers (Insert > Automatic Number > Section Number) can function as chapter numbers, and a List number, consisting of only one number, can be the automatic counter for the figures.

Here is a step-by-step instruction:

1. Insert a Section Break after each chapter.
2. If you now type "Figure " as a caption below the first figure, then insert a Section Number and type "-" after the Section Number, it looks as if we now only need to insert the List number
1.png
1.png (24.85 KiB) Viewed 8824 times
However, when the list number is inserted, it will be placed in front of the string for obvious reason because that's how lists are normally numbered; but that's not what you want. So for the caption you need to change the writing direction to "Right to Left Direction". Now the list number will appear correctly.

 After experimenting a little and based on the information you gave, I found out that you must create the first caption in the following order:


3. Insert the automatic List number
4. Then type "-"
5. Insert the Automatic Section Number (from Insert > Automatic Number > Section Number)
6. type " Figure"

.

This should now look like this (the gray number is the section number = chapter number):
2.png
2.png (24.91 KiB) Viewed 8824 times
7. Now select the caption and change the writing direction to "Right to Left Direction". The caption will be placed on the right side of your paper. Just choose Align Center to center it (if that happens to be the position you want to have it in). The caption should now have reached the format you want:
3.png
3.png (25.17 KiB) Viewed 8824 times
8. You can now copy and paste the caption. It will automatically appear in the new location exactly as you want it. If you don't want to continue numbering across the whole document, you need to adjust the list number manually once for every new chapter by selecting "Restart Numbering" from the Lists menu or the Lists palette.


9. Instead of copy and paste, I recommend creating a glossary entry consisting of the caption (including the "Right to Left Direction"). Give it a meaningful name (such as "fig", without the quotes), and every time you type "fig" in future and hit the spacebar your special capture will be immediately inserted when you need it. 


The page here says that you have just joined the forum. If you are new to Nisus, then you might want to know the following. The default lists that come with Nisus contain numbers with tabs and dots, but these lists— as well as almost everything else in Nisus—are highly customizable, and you can create as many new number lists as you want. If you have any questions regarding how to create a list with only one number (no tabs or dots), then just ask.




Þorvarður
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Captions with Chapter Number

Post by phspaelti »

Þorvarður wrote: If you have any questions regarding how to create a list with only one number (no tabs…
Well Þorvarður, now you have me curious. How do you create a list with no tabs?
philip
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Captions with Chapter Number

Post by adryan »

G’day, schac et al

I’ve never done this before, so I did some experimentation. It’s certainly not obvious how to proceed.

I, too, used a list and also faced the problem of prefixing the list item number with the chapter number. I managed to get it to work without using Þorvarður’s ingenious use of right-to-left text, only to discover I had done it for page numbers instead of chapter numbers. When I changed to section numbers, curious behavior was manifest; viz, clicking on a caption showed the correct numbering, but it reverted to the previous numbering when I clicked elsewhere in the document. So I’m not confident I can trust this list numbering system. It’s not inconceivable, either, that the RTL trick could fail in some future implementation of lists.

Relying on section numbers is also problematic when, as is often the case, a chapter may contain several sections.

In the end, my favored approach would be to use a relatively simple macro.

I would use as the caption for a figure something like “Figure QQQ Caption: Title”, where “QQQ” is a dummy constant and “Title” might be “View to starboard” for one figure and “View to port” for another, say. For a reference to a figure, I would write “Figure QQQ Reference: Title”, where once again “Title” would uniquely identify the figure.

En passant, this system has the advantages that you are sure you are referring to the correct figure and that it doesn’t matter if a reference precedes the figure in the manuscript. (I know that the cross-referencing system is supposed to take care of this latter point, but I like to keep things as transparent as possible: this way, I don’t have to keep checking that nothing has gone amiss.)

When all my figures were in the manuscript, I would duplicate the manuscript and run a macro that looped through each chapter:–

(1) update chapter number variable
(2) find each occurrence of “Figure QQQ Caption:”
(3) replace “QQQ” with a suitably incremented identifier that included chapter number and figure number in that chapter
(4) delete “ Caption”
(5) get the string representing the Title
(6) replace all occurrences of “Figure QQQ Reference: Title” with “Figure QQQ”, where the “QQQ” in the replacement string is now the identifier I used in Step (3)
(7) loop on getting to a new chapter

Clearly, this works regardless of how many section breaks one has in a chapter. All one needs is a clearly identifiable chapter number.

If I added a figure at a later date, I would either use a simple macro to increment relevant figure identifiers in the affected chapter and in the corresponding references, or I would add the figure to my duplicate manuscript and apply the original macro. Of course, the latter method assumes the manuscript hasn’t been altered in any other ways since applying the original macro.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Captions with Chapter Number

Post by Þorvarður »

phspaelti wrote:How do you create a list with no tabs?
You are right, Philip, I shouldn't have said that. What I meant was, reducing the space which separates text from the list number so that the tab becomes (almost) invisible. The red list number shows what I mean.

Sorry about the confusion.
1.png
1.png (30.25 KiB) Viewed 8796 times
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Captions with Chapter Number

Post by Þorvarður »

adryan wrote:Relying on section numbers is also problematic when, as is often the case, a chapter may contain several sections.
Absolutely correct; but the original poster was writing a paper, not a book, so perhaps he doesn't need sections for anything else. It would be good to get some feedback from him on this.

I tested my approach again today. This time it is the novel "Lord Jim" from Gutenberg with 45 chapters and 216 pages. It seems to work perfectly, as long as the problematic caption remains isolated on one line (paragraph). The image itself, however, can of course have many description lines, as long as they are separated from the problematic caption.
1.png
1.png (95.32 KiB) Viewed 8784 times
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Captions with Chapter Number

Post by Þorvarður »

adryan wrote:(1) update chapter number variable

(…) All one needs is a clearly identifiable chapter number.
How would you define such a chapter number variable?

__________
Þorvarður
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Captions with Chapter Number

Post by adryan »

G’day, Þorvarður et al

Depending on how one wishes to proceed, one can initialize a chapter number variable thus:–

$chapter = 0

or one can find it thus:–

Find 'Chapter ([[:digit:]]+)', 'E$', '-h'
$chapter = $1

A complexity with my proposed approach arises because image captions are not part of the main text and hence relating them to chapters is not trivial. I suspect one needs to look at the .anchorTextRange image object property, but alas I don’t have time at present to work this into a macro and test it.

It occurs to me that a slight modification of my proposed approach would be to devise a macro that operates on a document containing a single chapter. It would then be clear that all figures therein should have the same (easily discernible) chapter number prefix in their identifiers. The macro would then just increment figure numbers in the captions as it stepped through the figures. With all chapters reassembled into a single document, another macro would alter all the figure references appropriately. In fact, the whole operation could be handled by a single macro: chapter extraction → caption numbering → reassembly → reference numbering.

Some may find this approach somewhat clumsy, but to me the elegance lies in the transparency and the certainty that my numbering will be as I intended. Also, multiple-section chapters and multiple-line captions are easily accommodated.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Captions with Chapter Number

Post by phspaelti »

I just checked my earlier file with the list numbering approach, and I discovered that it had a problem, which I fixed.
adryan wrote:A complexity with my proposed approach arises because image captions are not part of the main text and hence relating them to chapters is not trivial. I suspect one needs to look at the .anchorTextRange image object property, but alas I don’t have time at present to work this into a macro and test it.
Indeed. Some people prefer to put the caption in a text box. Note that list numbers in Nisus work fine in text boxes. (See the updated file above.)
adryan wrote:It occurs to me that a slight modification of my proposed approach would be to devise a macro that operates on a document containing a single chapter. It would then be clear that all figures therein should have the same (easily discernible) chapter number prefix in their identifiers. The macro would then just increment figure numbers in the captions as it stepped through the figures…
If you make that assumption, you don't have to do any of this, since a simple list number will work fine. You can just write the chapter number as part of the preceding text. The whole point of the question, however, was the search for an automatic approach to the problem.
philip
schac
Posts: 4
Joined: 2015-03-03 03:06:39

Re: Captions with Chapter Number

Post by schac »

Hi all
Thank you so much for your various suggestions. I am a little bit overwhelmed with this, at least it seems to be a interesting problem. I will try to implement your solutions in a few days time when I am formatting my paper. For now, it is a rather short paper so I could easily add a section break per chapter.
I will post back on my success.
Cheers, schac
Post Reply