Skip to main content

How Can I Separately Number Different Types of Figures in My Book, Like Code Blocks and Tables, to Distinguish Them from Images?

Keywords: figure, figures, images, code blocks, tables

Leanpub Support avatar
Written by Leanpub Support
Updated yesterday

In a Leanpub manuscript written in Markua (our "Markdown for books"), some components are treated as "figures" by default, such as images, code blocks, and tables.

This affects how they appear in your book, how they're captioned, and how smart crosslinks refer to them.

In this article, we'll explain the default behavior for figure numbering etc., and how you can set code blocks and tables to be handled as different types of figures.

Specifically, you can set code blocks to be called "Listings" instead of "Figures", and you can set tables to be called "Tables" instead of "Figures".

Default Figure Behavior in a Leanpub Book

The following block elements are treated as figures unless otherwise specified:

- Images

- Code blocks

- Tables

When these elements are treated as figures:

- Their captions are prefixed with “Figure”, such as Figure 3.2

- Smart crosslinks use the label "Figure", such as `[#f](#fig-data-sample)` would display a crosslink along the lines of Figure 3. Figure Title

- They are included in the List of Figures, if you have added one to your book

Here is what an image with a caption will typically look like by default (though note this may vary with your selected book theme):

Here is what an code block with a caption will typically look like by default:

Here is what an table with a caption will typically look like by default:

Changing Figure Types

To customize how code blocks and tables are treated, you add a document-level setting at the beginning of your manuscript.

Changing Code Blocks from "Figures" to "Listings"

To change code blocks to be listed as "Listings" instead of "Figures", type this at the top of the first file in your manuscript, with a blank line below it:

{code-block-name: listing}

Now, your code blocks will appear as "Listings", like this:

Changing Tables from "Figures" to "Tables"

To change tables to be listed as "Tables" instead of "Figures", type this at the top of the first file in your manuscript, with a blank line below it:

{table-name: table}

Now, your tables will appear as "Tables", like this:

Changing Both Code Blocks and Tables in the Same Setting

You can use multiple documen-level settings at the top of the first file in your manuscript.

Here is how you would add both the code block and the table settings shown in this article to the top of your document, with a blank line below it:

{
code-block-name: listing
table-name: table
}

Example Manuscript

Here is the brief Markua manuscript used to generate the examples in this article, which includes pagebreak directives just for clarity of presentation, when you create a book from it:

{
code-block-name: listing
table-name: table
}

# Figure vs Listing vs Table

An image with a title:

{title: "Palm Trees"}
![](palm-trees.jpg)

{pagebreak}

A code block with a title:

{title: "Hello World in Ruby"}
```ruby
require 'time'
```

{pagebreak}

A table with a title:

{title: "Central Bank Rates"}
| Central Bank | Rate |
|--------------|-----------|
| JPY | -0.10% |
| EUR | 0.00% |
| USD | 0.00% |
| CAD | 0.25% |

Lists of Figures, Listing, and Tables

In addition to adding a list of figures to your manuscript, you can add a "List of Listings" and "List of Tables", if those features are enabled for code blocks and tables.

Here is how you would do it in the manuscript example above, where we've added the {figures}, {listings}, and {tables} directives on lines by themselves, just under the document-level settings at the top:

{
code-block-name: listing
table-name: table
}

{figures}
{listings}
{tables}

# Figure vs Listing vs Table

An image with a title:

{title: "Palm Trees"}
![](palm-trees.jpg)

{pagebreak}

A code block with a title:

{title: "Hello World in Ruby"}
```ruby
require 'time'
```

{pagebreak}

A table with a title:

{title: "Central Bank Rates"}
| Central Bank | Rate |
|--------------|-----------|
| JPY | -0.10% |
| EUR | 0.00% |
| USD | 0.00% |
| CAD | 0.25% |

Here's what the Table of Contents will show in the book:

Questions or Feedback

If you have any questions or feedback for this article, please email the Leanpub Team at hello@leanpub.com.


Subscribe to our YouTube channel! Growing our audience there really helps Leanpub authors like you get discovered! Plus you'll learn about other authors, and their experiences writing and publishing.

If you have any feedback or questions about this article, please email the Leanpub team about it at hello@leanpub.com!

If you have any questions or thoughts on writing and self-publishing with Leanpub, please join our global community of authors in our Authors Forum here!

Are you interested in self-publishing, and creating your first Leanpub book? Here are some quick tutorials for our most popular writing modes: http://help.leanpub.com/en/articles/3088382-quick-walkthroughs-for-getting-started-on-a-leanpub-book

Are you looking for great deals on Leanpub ebooks, ebook bundles, and courses? Sign up for our Weekly and Monthly newsletter sales here!

You can also follow Leanpub in lots of other places!

Did this answer your question?