How to center image caption in ASCIIDoctor

Problem

A caption to an image is provided in ASCIIDoctor document as follows:

.This is a caption
image::foo.png[align="center"]

However, the caption is aligned to the left by default.

Applying a text-center on it does not work:

[.text-center]
.This is a caption
image::foo.png[align="center"]

Solution

This problem has been discussed in this Github issue. The solution provided to add a few lines to imageblock in the stylesheet does not work. Instead, I changed the default behavior itself in the stylesheet to be center.

  • To do this first find out where gems are installed:
$ gem environment
  • Go to the INSTALLATION DIRECTORY output in the above command and to the subdirectory holds ASCIIDoctor stylesheets:
$ cd gems/asciidoctor-1.5.2/data/stylesheets/
  • Open the asciidoctor-default.css and find the place where for imageblock the text-align attribute is set to left and change that to center. For me, this was in line 177.

  • Rebuild your ASCIIDoctor document and the rendered HTML should have centered image caption.

Tried with: ASCIIDoctor 1.5.2, Ruby 2.1.0 and Ubuntu 14.04

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s