List of tables and figures in markdown / bookdown

Is it possible to automagically create a list of tables and figures in html reports?

So no latex tricks, as referenced here:

Something built on top of text / cross references?

(Trying to motivate someone to move from pdf to html reporting ...)

1 Like

I know it is possible using the pagedown format :

Which make sense because the HTML is paginated so you have a notion of page number you can reference in the list of table / figures.

For other HTML output format, it would require to be a list of tables / figures that could link back to the closest header link. But it would be formatted differently than usual list...

If you are looking to move from PDF using Latex to a more suited web format, pagedown is your tool. You can easily get a PDF file by printing the HTML document from a browser (or using pagedown::chrome_print

Thank you! Wasn't aware of that option. Looks promising!

1 Like

If you encounter any issues, have any feedbacks / ideas, please open issues in Github repo !

I'm not sure whether pagedown is the solution here, e.g. if we start with a bookdown project and want to create a page via bookdown::gitbook and not pagedown::html_paged. If there is not yet a functionality for list of figures (or tables) in pandoc (s. open proposal https://github.com/jgm/pandoc/issues/1965), do we have another way to achieve this, maybe by scraping the created html files in the last step and include the results in the bookdown website automatically (maybe after a second run or so)? Maybe this is a not a hard issue - or is it? Any ideas, experiences or solutions? Would be great to have a workaround for this issue before this gets implemented as a feature in pandoc which seems not too close yet. Thanks!

1 Like

Oh yes, if you are using bookdown, that won't be what you need.

Currently, there is no build in way to do that, but I hope we'll come up with something. List of Figures and Tables are only available to PDF output as built-in in Latex.

As I said above,

For other HTML output format, it would require to be a list of tables / figures that could link back to the closest header link. But it would be formatted differently than usual list...

It is not easy to know what should be done for a bookdown::gitbook() format. I am insterested in what you would expect the list of Tables and Figures to be like, as there will be no page number. Can you share your thoughts ?

When it will be built in Pandoc, it will surely be easy to do something about it in bookdown. For now, it would need to rely on a post processor step after the pdf has been generated, maybe couple with a lua filter as in pagedown. One trick is that the splitting process happens in R after pandoc conversion, so we need to know how files will be split and names to create link to them.

I got some ideas on that, but I willing to hear what you are wishing for as format and output.
Please feel free to open a feature request with this so we can discuss.

Currently there is one for building an index in HTML as in PDF (using latex)

Another project would be to have a way to transfrom a bookdown project to a pagedown output, so that it would be printable to PDF easily and maybe share some feature like those list of figure and table

Thanks for the suggestion !

Thanks for your considerations! I think this could work - maybe it's not even too hard for experienced web scrapers:

  • a list of figures (or tables) in html does not need to show a page number, only a link to the fig/tab.
  • These links, including the number and caption of the figs/tabs could be extracted from the html files of the book by parsing these html files and look for <table>and <img> tags (+ caption, etc.)
  • If we look at the built default bookdown project we find a table with all the information needed for a link: A table number ("2.1"), a Table caption "Here is a nice table!" and an id to link to (id="tab:nice-tab")
<table>
<caption><span id="tab:nice-tab">Table 2.1: </span>Here is a nice table!</caption>
<thead>
<tr class="header">
...

The same with images: Number ("2.1"), a caption (in the caption-class and also in the alt-text) ("Here is a nice figure!"), and an id (id="fig:nice-fig") (and even the path to the image).

<span id="fig:nice-fig"></span>
<img src="testbook_files/figure-html/nice-fig-1.png" alt="Here is a nice figure!" width="80%">
<p class="caption">
Figure 2.1: Here is a nice figure!
</p>
  • Thus we need a function that searches all the built html files for tables and figures, collects these data and saves it, together with the path (relative link to the html-file containing fig/tab) to a text/Rmd/html file, e.g. lof.html
  • Another function could look for such a file in the directory and pull it into the building process of the book at any position in the book, as Rmd or html.
  • The list of figures and tables should be generated in the end of the building process to catch all the html files and the tables und figures within. This means that it would take at least two runs of bookdown, but then the list of figures and tables would be comprehensive.

Am I missing something? If not, I'll be happy to make a feature request.
Thanks and all the best, G

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.