bashtage / sphinx-material

A material-based, responsive theme inspired by mkdocs-material
Other
317 stars 91 forks source link

Images not aligned to center when :align: center is specified #64

Closed johnthagen closed 4 years ago

johnthagen commented 4 years ago

If I create some RST like:

.. image:: ../my_image.png
  :align: center
  :scale: 60%

I noticed that unlike vanilla Sphinx the image is not aligned to the center of the page, and is still right justified instead.

johnthagen commented 4 years ago

I played around and confirmed that other .. image:: directives, like :scale: do work. Only one that I can find that doesn't work is :align:.

johnthagen commented 4 years ago

@bashtage I'd like to try to help out with this issue. Could you point me in the direction where this would be added/fixed?

johnthagen commented 4 years ago

I was able to reproduce this on the demo site but updating docs/index.rst to:

===================
Material for Sphinx
===================

.. image:: images/screenshot.png
    :alt: Material for Sphinx Screenshots
    :scale: 20%
    :align: center

...

Note that image is not aligned to center. Also right does not align it to the right.

material-bug
johnthagen commented 4 years ago

When I inspect the element, I see that the align-center class is being applied, so perhaps just some CSS is missing?

inspect-material
johnthagen commented 4 years ago

Built example in case someone wants to manually inspect the output:

bashtage commented 4 years ago

I assume that there is no css for img.align-center or img.align-right.

johnthagen commented 4 years ago

Thanks, where would the best place to add this be?

johnthagen commented 4 years ago

Confirmed that the CSS was missing. I was able to temporarily work around this issue by including the following custom CSS in my Sphinx project:

# conf.py
def setup(app) -> None:
    app.add_css_file('css/custom.css')
/* custom.css */
.align-center {
  display: block;
  margin-left: auto;
  margin-right: auto;
}
johnthagen commented 4 years ago

It appears that .. list-table:: are not also aligned when sphinx-material is applied.

.. list-table:: Table
   :header-rows: 1
   :align: center

   ...