Figure and Table numbering

shudson310
Posts: 130
Location: USA

Figure and Table numbering

Thu Jun 28, 2018 11:05 pm

I'm trying to auto-number figures and tables, but the counter doesn't increment. Here's my code:

Code: Select all

body {
  counter-reset: figures 1;
  counter-reset: tables 1; 
}

*[class ~= "topic/fig"] { 
    counter-increment: figures;
}

*[class ~= "topic/fig"] figcaption::before {
    content: "Figure " counter(figures) ": ";
  }
 
table {   
    counter-increment: tables;
}

table caption::before {
    counter-increment: tables;
    content: "Table " counter(tables) ": ";
  }


Every figure in the doc is Figure 1 right now...
Scott Hudson
Content Strategist
Jeppesen
Site: jeppesen.com
Dan
Posts: 299

Re: Figure and Table numbering

Fri Jun 29, 2018 12:46 pm

There are two solutions:

1. You are using the pdf-css-html5 transformation. With this you should get automatically the numbers of the tables before the table titles, with no change in your CSS file. However, I just learned that there is a "com.oxygenxml.html.custom" plugin in the DITA-OT directory that removes the figure numbers. You can delete this plugin from your DITA-OT installation (I recommend to copy the DITA-OT from oXygen to another location where you have write access, then change the DITA-OT directory option from the oXygen preferences).
Important: The numbering works if the figures and tables have titles.

2. Other workaround, using CSS (I would go for this...):

There are two problems in your CSS with the counter reset:
  • You are using the same counter-reset property twice in the CSS rule. The last one will override the first one. One should use a single property and separate the counter reset values with comma.
  • The body element will be replicated in all page sequences, so you will get more counter resets than expected.

Fortunately there are already some counters initialized on the root of the document: figcount and tablecount so you will not to define yours. You can use them like this:

Code: Select all


*[class ~= "topic/fig"] {
    counter-increment: figcount;
}

*[class ~= "topic/fig"] figcaption::before {
    content: "Figure " counter(figcount) ": ";
}
 
*[class ~= "topic/table"]{   
    counter-increment: tablecount;
}

*[class ~= "topic/table"] caption::before {
    content: "Table " counter(tablecount) ": ";
}

/* Hide the labels generated by DITA-OT */
.table--title-label,
.figtitleprefix {
    display:none;
}



Best regards,
Dan
shudson310
Posts: 130
Location: USA

Re: Figure and Table numbering

Fri Jun 29, 2018 4:26 pm

Worked like a charm. As always, you oXygen folks are the best!

Many thanks!
Scott Hudson
Content Strategist
Jeppesen
Site: jeppesen.com
annyjul
Posts: 3

Re: Figure and Table numbering

Wed Jul 11, 2018 12:02 pm

Dan wrote:There are two solutions:
...
Fortunately there are already some counters initialized on the root of the document: figcount and tablecount so you will not to define yours. You can use them like this:

Code: Select all


*[class ~= "topic/fig"] {
    counter-increment: figcount;
}

*[class ~= "topic/fig"] figcaption::before {
    content: "Figure " counter(figcount) ": ";
}
 
*[class ~= "topic/table"]{   
    counter-increment: tablecount;
}

*[class ~= "topic/table"] caption::before {
    content: "Table " counter(tablecount) ": ";
}

/* Hide the labels generated by DITA-OT */
.table--title-label,
.figtitleprefix {
    display:none;
}



Best regards,
Dan


Hi, I'm very sorry for stupid question, but I need figure/table numbering too. I'm still learning dita/oxygen.
Dan, I copy-pasted your code to css file, and linked this file via arg.css to Dita Map Web Help Responsive scenario. Table numbering works, but figures numbering doesn't. What am I missing?
Radu
Posts: 5692

Re: Figure and Table numbering

Wed Jul 11, 2018 1:40 pm

Hi,

This particular discussion thread is about generating PDF from DITA content using CSS. So you should not use its advice for the WebHelp Responsive output.
Coming back to the WebHelp responsive output, we took the decision not to show numbers for figures for HTML-based output because the numbering is started from "1" for each HTML file which results in the output folder. So if for the first topic in the map you will have Figure 1 and Figure 2, for the second topic you will have again Figure 1 and Figure 2.
So, because for each DITA topic an HTML equivalent is generated, you will not get the numbering to continue from the first topic to the last topic in the publication, like you would when you generate the PDF.
If knowing about this limitation you still want to show the figure count next to the title, I can give you some steps to do that.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
annyjul
Posts: 3

Re: Figure and Table numbering

Thu Aug 02, 2018 9:17 am

Radu wrote:Hi,

This particular discussion thread is about generating PDF from DITA content using CSS. So you should not use its advice for the WebHelp Responsive output.
Coming back to the WebHelp responsive output, we took the decision not to show numbers for figures for HTML-based output because the numbering is started from "1" for each HTML file which results in the output folder. So if for the first topic in the map you will have Figure 1 and Figure 2, for the second topic you will have again Figure 1 and Figure 2.
So, because for each DITA topic an HTML equivalent is generated, you will not get the numbering to continue from the first topic to the last topic in the publication, like you would when you generate the PDF.
If knowing about this limitation you still want to show the figure count next to the title, I can give you some steps to do that.

Regards,
Radu


I'm fine with those limitations, but i need numberibg to reference picture ( "as shown in the picture N" ) even If it's for each topic. I export to pdf and web, so I would need to change text of reference specifically for web output.
What so I need to change to get figure numbering in web? Thanks!
Radu
Posts: 5692

Re: Figure and Table numbering

Tue Aug 07, 2018 1:44 pm

Hi,

Sorry for the delay.
If you edit the Oxygen transformation scenario, in the Parameters list there is a parameter called "args.figurelink.style" which you can set to "NUMTITLE".

https://www.dita-ot.org/2.0/readme/ant-parameters-all-transformation-types.html

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “Common Problems”

Who is online

Users browsing this forum: No registered users and 0 guests