Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting in pandoc 2, figures without captions are left-justified in PDF output #4483

Closed
nsheff opened this issue Mar 22, 2018 · 7 comments
Closed

Comments

@nsheff
Copy link

nsheff commented Mar 22, 2018

I am producing PDF output from markdown source.

In pandoc 1, figures without captions were centered by default. In pandoc 2, figures without captions are left-justified.

Was this change intended? I did not see documentation of this change in the release notes. I believe this is a bug and figures without captions should be centered in pandoc 2.

Reproducible example:

image.md:

# Here's an image:

![](example_figure.png)

example_figure.png:
example_figure

command: `pandoc image.md -o image.pdf

Result under pandoc1: image.pdf

Result under pandoc2: image-pandoc2.pdf

@nsheff nsheff changed the title Starting in pandoc 0.2, images without captions are left-justified Starting in pandoc 2, images without captions are left-justified Mar 22, 2018
@nsheff nsheff changed the title Starting in pandoc 2, images without captions are left-justified Starting in pandoc 2, images without captions are left-justified in PDF output Mar 22, 2018
@nsheff nsheff changed the title Starting in pandoc 2, images without captions are left-justified in PDF output Starting in pandoc 2, figures without captions are left-justified in PDF output Mar 22, 2018
@jgm
Copy link
Owner

jgm commented Mar 22, 2018 via email

@jgm jgm closed this as completed Mar 22, 2018
@jpeacock29
Copy link

Unfortunately, adding a non-breaking space still triggers "Figure 1:" as the caption. Any other suggestions for a work around here? It seems odd that images in pdfs are centered with a caption and left justified without; would you consider a pull request to center all images in pdfs? Thanks!

@trou
Copy link

trou commented Nov 25, 2020

For those having the problem, adding a Zero-width space does the trick.
You can copy the following text (​) and remove the parenthesis.

@nacaru-w
Copy link

I wonder if there have been any developments on this. I have tried a thousand ways to do it and still can't make it work.

@jgm
Copy link
Owner

jgm commented May 17, 2024

You could achieve this with a Lua filter:
https://pandoc.org/lua-filters.html#center-images-in-latex-and-html-output

@nacaru-w
Copy link

Alright. I finally found a way. I'll leave the answer here for everyone else to see (worked for me in Pandoc 3.1.9):

Using the Lua filter alone will add an unnecessary caption (images with captions are centered by default), so you need to:

  1. Create a .lua file (for example, center.lua) that contains the following code:
-- Filter images with this function if the target format is LaTeX.
if FORMAT:match 'latex' then
  function Image (elem)
    -- Surround all images with image-centering raw LaTeX.
    return {
      pandoc.RawInline('latex', '\\hfill\\break{\\centering'),
      elem,
      pandoc.RawInline('latex', '\\par}')
    }
  end
end
  1. Remove the implicit_figures plugin when you make the Pandoc call to convert the file, make sure to add the filter to the call:
pandoc --lua-filter=center.lua <YOUR FILE>.md -fmarkdown-implicit_figures -o <OUTPUT FILE>.pdf

Adding a fake caption and then removing the plugin, as some in StackOverflow have suggested, won't work (image sticks to the left).

@jgm
Copy link
Owner

jgm commented May 17, 2024

Instead of -implicit_figures, you could have the Lua filter set the images caption to {}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants