Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to center image caption in ASCIIDoctor

📅 2015-Sep-03 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ asciidoctor, caption, image ⬩ 📚 Archive

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.

$ gem environment
$ cd gems/asciidoctor-1.5.2/data/stylesheets/

Tried with: ASCIIDoctor 1.5.2, Ruby 2.1.0 and Ubuntu 14.04


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧