Skip to content

Commit

Permalink
Fix sphinx-doc#4550: html: Centering tables by default using CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed May 6, 2019
1 parent 035d550 commit 43c9c51
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Incompatible changes
API directly
* #6230: The anchor of term in glossary directive is changed if it is consisted
by non-ASCII characters
* #4550: html: Centering tables by default using CSS

Deprecated
----------
Expand Down
2 changes: 1 addition & 1 deletion sphinx/templates/latex/longtable.tex_t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
\begin{savenotes}\sphinxatlongtablestart\begin{longtable}
<%- if table.align == 'center' -%>
<%- if table.align in ('center', 'default') -%>
[c]
<%- elif table.align == 'left' -%>
[l]
Expand Down
2 changes: 1 addition & 1 deletion sphinx/templates/latex/tabular.tex_t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
\begin{savenotes}\sphinxattablestart
<% if table.align -%>
<%- if table.align == 'center' -%>
<%- if table.align in ('center', 'default') -%>
\centering
<%- elif table.align == 'left' -%>
\raggedright
Expand Down
2 changes: 1 addition & 1 deletion sphinx/templates/latex/tabulary.tex_t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
\begin{savenotes}\sphinxattablestart
<% if table.align -%>
<%- if table.align == 'center' -%>
<%- if table.align in ('center', 'default') -%>
\centering
<%- elif table.align == 'left' -%>
\raggedright
Expand Down
15 changes: 15 additions & 0 deletions sphinx/themes/basic/static/basic.css_t
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ img.align-center, .figure.align-center, object.align-center {
margin-right: auto;
}

img.align-default, .figure.align-default {
display: block;
margin-left: auto;
margin-right: auto;
}

.align-left {
text-align: left;
}
Expand All @@ -297,6 +303,10 @@ img.align-center, .figure.align-center, object.align-center {
text-align: center;
}

.align-default {
text-align: center;
}

.align-right {
text-align: right;
}
Expand Down Expand Up @@ -368,6 +378,11 @@ table.align-center {
margin-right: auto;
}

table.align-default {
margin-left: auto;
margin-right: auto;
}

table caption span.caption-number {
font-style: italic;
}
Expand Down
2 changes: 1 addition & 1 deletion sphinx/transforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def apply(self, **kwargs):
# type: (Any) -> None
matcher = NodeMatcher(nodes.table, nodes.figure)
for node in self.document.traverse(matcher): # type: nodes.Element
node.setdefault('align', 'center')
node.setdefault('align', 'default')


class FilterSystemMessages(SphinxTransform):
Expand Down
1 change: 1 addition & 0 deletions sphinx/writers/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,7 @@ def visit_image(self, node):
(1, 'middle'): ('\\raisebox{-0.5\\height}{', '}'),
(1, 'bottom'): ('\\raisebox{-\\height}{', '}'),
(0, 'center'): ('{\\hspace*{\\fill}', '\\hspace*{\\fill}}'),
(0, 'default'): ('{\\hspace*{\\fill}', '\\hspace*{\\fill}}'),
# These 2 don't exactly do the right thing. The image should
# be floated alongside the paragraph. See
# https://www.w3.org/TR/html4/struct/objects.html#adef-align-IMG
Expand Down

0 comments on commit 43c9c51

Please sign in to comment.