Left or Right margin TOC

In this tutorial, we will learn how to add a table of contents in the left/right hand margin of an article or book document.

Table of Contents

Left/Right margin Table Of Contents (TOC)

This TOC is located in the left or right side of the main content of the document.

Example of Asciidoc document
= My Document

== Here are my first table of contents

=== Why not another chapter

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus condimentum dui id lectus viverra placerat.
Sed arcu ipsum, posuere et scelerisque ac, eleifend id turpis. Ut vitae velit congue,
sollicitudin nisi eu, vestibulum lorem. Praesent lectus turpis, ullamcorper vehicula volutpat interdum,
vestibulum condimentum elit. Aliquam erat volutpat. Donec vulputate, dolor vitae molestie convallis,
lacus elit auctor ipsum, sed pharetra augue justo id nisl. Vivamus imperdiet neque ac nunc malesuada,
nec semper mauris viverra. Morbi venenatis ornare dictum. In pulvinar pellentesque felis,
a bibendum mauris tempus interdum. Vestibulum vehicula diam id dolor tincidunt consequat.
Fusce quis enim ultrices metus tincidunt malesuada. Vestibulum at placerat dolor.
Aliquam venenatis aliquam mi sit amet cursus. Donec condimentum dolor ut posuere condimentum.
Vivamus viverra nisl massa. Quisque turpis mauris, ultricies at vehicula nec, ultricies dictum tellus.

You will used the standard toc2 attribute of AsciiDoc. See http://www.methods.co.nz/asciidoc/userguide.html#X91

Result with flatly theme

With this theme we will put a TOC in right margin of the document

Enter the following command:

$ asciidoc -b bootstrap -a bsver=2 -a theme=flatly -a toc2 -a numbered -a sidebar=right -a jumbotron-fullwidth /path/to/document/demo.asciidoc

And here are the final result that you should get.

Figure 1. My first TOC2 with flatly theme

Result with default theme

With this theme we will put a TOC in left margin of the document (default behavior).

Enter the following command:

$ asciidoc -b bootstrap -a bsver=2 -a theme=default -a toc2 -a numbered -a sidebar=left -a jumbotron-fullwidth /path/to/document/demo.asciidoc
Note
  • sidebar attribute is optional in this situation (left margin).

  • theme attribute is optional in this situation (default theme is always bs2default).

And here are the final result that you should get.

Figure 2. My first TOC2 with default theme