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

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

Closed
johnthagen opened this issue Sep 1, 2020 · 9 comments · Fixed by #70
Closed

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

johnthagen opened this issue Sep 1, 2020 · 9 comments · Fixed by #70

Comments

@johnthagen
Copy link
Contributor

johnthagen commented Sep 1, 2020

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 johnthagen changed the title Images not aligned to center when specified Images not aligned to center when :align: center is specified Sep 1, 2020
@johnthagen
Copy link
Contributor Author

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
Copy link
Contributor Author

@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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@bashtage
Copy link
Owner

bashtage commented Sep 7, 2020

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

@johnthagen
Copy link
Contributor Author

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

@johnthagen
Copy link
Contributor Author

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
Copy link
Contributor Author

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

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

   ...

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

Successfully merging a pull request may close this issue.

2 participants