asciidoctor / asciidoctor-pdf

:page_with_curl: Asciidoctor PDF: A native PDF converter for AsciiDoc based on Asciidoctor and Prawn, written entirely in Ruby.
https://docs.asciidoctor.org/pdf-converter/latest/
MIT License
1.14k stars 500 forks source link

How to make the title of image be center? #790

Closed fly7632785 closed 4 years ago

fly7632785 commented 7 years ago

Hi, everybody. I'm using asciidoctor-pdf to generate pdf. But I want to know how to make the title of image be center? Thanks

mojavelinux commented 7 years ago

Currently it's only possible to align block captions globally using the theme file. See https://github.com/asciidoctor/asciidoctor-pdf/blob/master/docs/theming-guide.adoc#keys-caption

It's not currently possible to control the caption position per block. This is likely something we first need to resolve in Asciidoctor core. It looks like you already found it, though. See https://github.com/asciidoctor/asciidoctor/issues/857.

fly7632785 commented 7 years ago

all right , thanks

dohliam commented 4 years ago

For anyone else who finds this and is wondering how to go about doing this quickly, it's actually fairly simple. Just create a file called theme.yml with the following contents:

extends: default
image:
  align: center
caption:
  align: center

Then create your PDF using the following command:

asciidoctor-pdf -a pdf-style=theme.yml your_document.adoc

mojavelinux commented 4 years ago

@dohliam you are absolutely correct, this can be controlled by the theme. What's more, in 1.5.0-rc.2, you can configure the caption alignment to inherit from the image alignment.

extends: default
image:
  caption:
    align: inherit

Then you'd define a block image as follows:

image::filename.png[align=center]

Now both the image and caption will be aligned to the center.

What's not possible is to control the alignment of the caption from the AsciiDoc. It can only be controlled by the theme.

acebone commented 3 years ago

I'm having this exact problem.

I've gotta say it makes no sense that the image-caption is not contained in the same html-block (the same div) as the image. How many use cases are there, where somebody goes: "I'd like my image to be right-aligned, but I want the caption to be much wider than the image, and I want it in the center"

Screenshot from 2020-11-17 15-21-15

I can see from my searches that a lot of people are annoyed by this, and rightfully so, I must say. Are anybody working on this issue?

mojavelinux commented 3 years ago

@acebone I don't like the aggressive tone of your comment. It's not welcome here. If you ask again in a constructive way without the insults, I'd be happy to walk you through how to achieve the result you want.

acebone commented 3 years ago

I'm sorry - I was very annoyed at the time, I can totally understand you resenting that way of addressing others. It's simply not ok. I don't usually respond in that way, and I'll make an effort to see that it will not happen again.

I am wrong btw. The markup is as it should be, so the fix lies in CSS.

Once again Dan, I do apologize

Den tir. 17. nov. 2020 kl. 20.33 skrev Dan Allen notifications@github.com:

I don't like the aggressive tone of your comment. It's not welcome here. If you ask again in a constructive way without the insults, I'd be happy to walk you through how to achieve the result you want.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/asciidoctor/asciidoctor-pdf/issues/790#issuecomment-729153549, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABFJZOY2DG6H65IVRVXGY3SQLFYRANCNFSM4DFM3M7A .

pvnhome commented 2 years ago

In AsciidocFX:

image

In theme.yml (as @mojavelinux suggest):

extends: default
image:
  caption:
    align: inherit
patrislav1 commented 6 months ago

In case anyone else is stumbling over this, both the theme syntax and CLI options appear to have changed - the solution with current asciidoctor-pdf (2.3.15) is:

extends: default
image:
  caption-align: inherit
asciidoctor-pdf --theme theme.yml your_document.adoc
wmat commented 6 months ago

Add this to the theme:

image: caption: align: center

On Tue, Apr 9, 2024 at 10:19 AM Patrick Huesmann @.***> wrote:

I can't get this to work with current asciidoctor-pdf version, the caption is always left aligned - am I missing something?

$ asciidoctor-pdf -V Asciidoctor PDF 2.3.15 using Asciidoctor 2.0.22 [https://asciidoctor.org] Runtime Environment (ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]) (lc:UTF-8 fs:UTF-8 in:UTF-8 ex:UTF-8) $ cat theme.yml extends: default image: caption: align: inherit $ asciidoctor-pdf -a pdf-style=theme.yml output.adoc asciidoctor: WARNING: output.adoc: line 834: unterminated listing block asciidoctor: WARNING: output.adoc: line 864: unterminated example block asciidoctor: WARNING: output.adoc: line 958: unterminated listing block /var/lib/gems/2.7.0/gems/prawn-svg-0.34.2/lib/prawn/svg/elements/image.rb:68: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /var/lib/gems/2.7.0/gems/prawn-svg-0.34.2/lib/prawn/svg/elements/base.rb:94: warning: The called method `add_call' is defined here$

.Image caption text which I can't get to center-alignimage::media/image.svg[alt-text,width=220,align="center"]

(Doesn't change if I replace align: inherit by align: center in the theme.yml)

— Reply to this email directly, view it on GitHub https://github.com/asciidoctor/asciidoctor-pdf/issues/790#issuecomment-2045297513, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAN6ZAUI3IQW72VQTRI4X3Y4P2GTAVCNFSM4DFM3M7KU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBUGUZDSNZVGEZQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

patrislav1 commented 6 months ago

Add this to the theme: image: caption: align: center

That didn't work. but I found the actual solution in the meantime (see my edited post above)

mojavelinux commented 6 months ago

Please direct follow-ups to the project chat at https://chat.asciidoctor.org. The issue tracker is not a discussion forum. Thanks.