6

I want to center an image in my project's GitHub README.org file, but everything I've tried so far hasn't worked:

#+ATTR_HTML style="center"
[[/path/to/img.png]]


#+ATTR_HTML align="center"
[[/path/to/img.png]]

#+begin_center
[[/path/to/img.png]]
#+end_center

Is this possible, or should I just go the low-friction route and use Markdown?

Alex Shroyer
  • 627
  • 4
  • 12

2 Answers2

6

You can embed "raw" html as follows:

<p align="center"><img src="images/wim-128.png" /></p>

When displayed on GitHub.com, for some reason org-mode's image styling directives are ignored.

However GitHub does not ignore styling of <p> tags, so I used the above fix.

Alex Shroyer
  • 627
  • 4
  • 12
5

To center with CSS, you need to use margin-left: auto; and margin-right: auto;

try this

#+ATTR_HTML: :style margin-left: auto; margin-right: auto;
[[/path/to/img.png]]
Xah Lee
  • 1,756
  • 12
  • 11
  • 1
    When I did this I end up with the text `#+ATTR_HTML ...` visible in the rendered [README](https://github.com/hoosierEE/wim/blob/1e3f0d5667eeb13d6fd20eeea95df4a1f8c705d6/README.org). – Alex Shroyer Sep 11 '16 at 15:17
  • 1
    @hoosierEE i modified the answer so the solution should be correct. I tried it and it works. – Xah Lee Sep 12 '16 at 21:57
  • 1
    I guess either GitHub's version of [org-ruby](https://github.com/bdewey/org-ruby), or their own CSS, removes these styles before rendering on github.com. Thanks for trying though, and by the way I really like your ErgoEmacs site! – Alex Shroyer Sep 13 '16 at 19:40
  • 1
    @hoosierEE thanks, and glad you found the answer. I forgot about the github layer. – Xah Lee Sep 14 '16 at 19:52