Repository navigation
#3377: support :align: option for tables - #3405
Conversation
| @@ -1,3 +1,11 @@ | |||
| <%- if table.align -%> | |||
There was a problem hiding this comment.
OMG, I'd forgotten to review the rendering result of longtable.
It doesn't work. I will update this later.
There was a problem hiding this comment.
Yes you can't wrap longtable in table
| @@ -1,3 +1,11 @@ | |||
| <%- if table.align -%> | |||
| \begin{table}[htb] | |||
There was a problem hiding this comment.
I used table, flushleft and flushright environments to align tables.
But they only adjust alignments. we can't wrap text around the table.
Is it better to use wraptable?
| <%- endif %> | ||
| <% endif -%> | ||
| <%- if table.caption -%> | ||
| \begin{threeparttable} |
There was a problem hiding this comment.
I think there are no reason to use threeparttable any longer.
Because we don't use the third part; tablenotes.
To this opportunity, it would be nice to move table environment to display captions. What do you think?
- Pros.
- simple (lesser environements)
- Cons.
- tables always become float
There was a problem hiding this comment.
The advantage of threeparttable is that it handles the caption automatically. But its notion of tablenotes causes it to patch the tabular or tabulary, hence if one wants to use tabu one would have to try to imitate which is low-level LaTeX hacking. If we don't use threeparttable we can emulate without too much difficulty the treatment of the caption (already Sphinx loads capt-of package which facilitates use of \caption outside of reguler table environment). In fact threeparttable wraps the caption to the natural width of the tabular, which is not so interesting if text is not allowed to flow around it. In conclusion, dropping threeparttable does not mean we have to switch to table. We can do it by our own means without using regular LaTeX floats. I don't think I have time today, but I will look tomorrow.
There have been some requests (I lost reference) on Sphinx issue tracker to let the table floats in PDF output. I think this can indeed be made a new config option. But longtable is not a float and (not tested, but I expect that) it can not be wrapped in table. In fact a LaTeX table is an object which at some point should appear without any page break on one page. longtable to the contrary allows page breaks. It can thus not float in the LaTeX technical sense. There is no "float" in LaTeX which is multi-page. Thus if we start having use of table for smaller tables we may end up in situation that sometimes for some mysteriousreason the small table will be printed 3 pages later after the very long longtable coming next. This means it is important that H specifier is available if we do that.
Sorry for very long explanation only to say that:
-
we can handle captions after having dropped
threeparttableand without switching totable, -
we can switch to
tablebutlongtablewill remain as is, -
the switch to
tableshould possibly be made a config option,-
and if True, then user should be able to use H specifier in some cases but not necessarily all the time in the document,
-
if user does not say to make table float, it is like current situation, or like saying table floats but use H specifier all the time; hence I think it should not be a possibility for user to say to use table floats with H specifier all the time, in such case, the user must use default behaviour that tables are not (LaTeX) floats.
-
There was a problem hiding this comment.
In the end I changed my mind about the last point, because I agree the simple thing to do is remove threeparttable use completely and use always table (except for longtable) and so we naturally must allow user config to be H all the time, if only because this is how to best emulate current Sphinx behaviour.
| # table having :align: option (tabulary) | ||
| table = tables['table having :align: option (tabulary)'] | ||
| assert ('\\begin{table}[htb]\\centering\n' | ||
| '\\noindent\\begin{tabulary}{\\linewidth}{|L|L|}\n' in table) |
There was a problem hiding this comment.
There might be no effect in this case... The table is too wide to align holizontal.
| # table having :align: option (tabular) | ||
| table = tables['table having :align: option (tabular)'] | ||
| assert ('\\begin{table}[htb]\\begin{flushleft}\n' | ||
| '\\noindent\\begin{tabular}{|\X{30}{100}|\X{70}{100}|}\n' in table) |
There was a problem hiding this comment.
Do this \noindent have any effects? Should it be removed?
| @@ -1,3 +1,11 @@ | |||
| <%- if table.align -%> | |||
| \begin{table}[<%= table_align %>] | |||
There was a problem hiding this comment.
Note:
For figure directive, :align: option makes the figure float.
align : "left", "center", or "right"
The horizontal alignment of the figure, allowing the image to float and have the text flow around it. The specific behavior depends upon the browser or rendering software used.
http://docutils.sourceforge.net/docs/ref/rst/directives.html#figure
But, for table directives, the definition does not mention about float. So we should not wrap text around the table even if aligned.
align : "left", "center", or "right"
The horizontal alignment of the table. (New in Docutils 0.13)
http://docutils.sourceforge.net/docs/ref/rst/directives.html#table
There was a problem hiding this comment.
There is a clash of vocabulary between Docutils and LaTeX. When LaTeX says "float", it means something which is disconnected from the text flow and may appear at various locations, according to some algorithm which creates lots of misunderstandings in the use of h, t, b, p specifier. Further, LaTeX floats have an associated counter and an associated \listof<foo> command. I am not aware of any general solution to have a genuine "LaTeX float" which when positioned will allow text flowing around it either to left, right, or around: the wrapfig package handles both figures and tables the objects are then not reguler LaTeX floats, although wrapfig arranges for them to appear in the \listof<table|figure>, more importantly for us it is a fragile thing which is not compatible with being used in lists, which Sphinx uses a lot, although I have a hack around that but I don't feel like it is robust enough. The threeparttable also creates mock float objects: they may have a caption and will show in the \listoftable. Similarly longtable is not a regular LaTeX float, but it may have a caption which will show in \listoftable.
The Docutils "float" presumably refers to HTML/CSS notion. I do not quite understand from Docutils description what is intended exactyt by "left", "center", "right", but naive interpretation on LaTeX side is not to create LaTeX floats, but simply adjust the use of threeparttable to get the desired horizontal alignment. longtable has corresponding optional parameter which can be used.
Thus making tables float in the LaTeX sense in Sphinx is not directly related to problem of Docutils :align: option.
| @@ -1,3 +1,11 @@ | |||
| <%- if table.align -%> | |||
| \begin{table}[<%= table_align %>] | |||
There was a problem hiding this comment.
There is a clash of vocabulary between Docutils and LaTeX. When LaTeX says "float", it means something which is disconnected from the text flow and may appear at various locations, according to some algorithm which creates lots of misunderstandings in the use of h, t, b, p specifier. Further, LaTeX floats have an associated counter and an associated \listof<foo> command. I am not aware of any general solution to have a genuine "LaTeX float" which when positioned will allow text flowing around it either to left, right, or around: the wrapfig package handles both figures and tables the objects are then not reguler LaTeX floats, although wrapfig arranges for them to appear in the \listof<table|figure>, more importantly for us it is a fragile thing which is not compatible with being used in lists, which Sphinx uses a lot, although I have a hack around that but I don't feel like it is robust enough. The threeparttable also creates mock float objects: they may have a caption and will show in the \listoftable. Similarly longtable is not a regular LaTeX float, but it may have a caption which will show in \listoftable.
The Docutils "float" presumably refers to HTML/CSS notion. I do not quite understand from Docutils description what is intended exactyt by "left", "center", "right", but naive interpretation on LaTeX side is not to create LaTeX floats, but simply adjust the use of threeparttable to get the desired horizontal alignment. longtable has corresponding optional parameter which can be used.
Thus making tables float in the LaTeX sense in Sphinx is not directly related to problem of Docutils :align: option.
| <%- endif %> | ||
| <% endif -%> | ||
| <%- if table.caption -%> | ||
| \begin{threeparttable} |
There was a problem hiding this comment.
The advantage of threeparttable is that it handles the caption automatically. But its notion of tablenotes causes it to patch the tabular or tabulary, hence if one wants to use tabu one would have to try to imitate which is low-level LaTeX hacking. If we don't use threeparttable we can emulate without too much difficulty the treatment of the caption (already Sphinx loads capt-of package which facilitates use of \caption outside of reguler table environment). In fact threeparttable wraps the caption to the natural width of the tabular, which is not so interesting if text is not allowed to flow around it. In conclusion, dropping threeparttable does not mean we have to switch to table. We can do it by our own means without using regular LaTeX floats. I don't think I have time today, but I will look tomorrow.
There have been some requests (I lost reference) on Sphinx issue tracker to let the table floats in PDF output. I think this can indeed be made a new config option. But longtable is not a float and (not tested, but I expect that) it can not be wrapped in table. In fact a LaTeX table is an object which at some point should appear without any page break on one page. longtable to the contrary allows page breaks. It can thus not float in the LaTeX technical sense. There is no "float" in LaTeX which is multi-page. Thus if we start having use of table for smaller tables we may end up in situation that sometimes for some mysteriousreason the small table will be printed 3 pages later after the very long longtable coming next. This means it is important that H specifier is available if we do that.
Sorry for very long explanation only to say that:
-
we can handle captions after having dropped
threeparttableand without switching totable, -
we can switch to
tablebutlongtablewill remain as is, -
the switch to
tableshould possibly be made a config option,-
and if True, then user should be able to use H specifier in some cases but not necessarily all the time in the document,
-
if user does not say to make table float, it is like current situation, or like saying table floats but use H specifier all the time; hence I think it should not be a possibility for user to say to use table floats with H specifier all the time, in such case, the user must use default behaviour that tables are not (LaTeX) floats.
-
|
Posting this LaTeX code snippet as illustration of some aspects of \documentclass{article}
\usepackage{threeparttable}
\begin{document}
\listoftables
text before
\begin{table}[htbp]
% try with caption here
% \caption{FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO }
\centering
\begin{threeparttable}
\caption{FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO FOO }
\begin{tabular}{cc}
A&A
\end{tabular}
\end{threeparttable}
\end{table}
text after
% 'naked' threeparttable is flush left (it does not need \noindent.) It is
% actually an inline object, which by defaults has baseline at its TOP.
some text before
\begin{threeparttable}
\caption{FOO FOO FOO FOO FOO}
\begin{tabular}{cc}
A&A
\end{tabular}
\end{threeparttable} final text in same paragraph shows it is inline object
final text in same paragraph shows it is inline object final text in same
paragraph shows it is inline object final text in same paragraph shows it is
inline object
\end{document} |
jfbu
left a comment
There was a problem hiding this comment.
Sorry for being so verbose ...
-
I agree to drop
threeparttable, one only needs to remove the corresponding template lines ... (thanks to your earlier PR ...) -
I expect that
Hspecifier if used systematically provides very similar result as so far obtained viathreeparttable. My initial move would thus to makeHthe default fortable_alignconfig value. But it is also ok to havehtbpas default. -
there should be a way for fine tuning to pass locally to a given table the LaTeX float positioning like
bporH. -
One should not say
alignmenthere because it creates confusion. In this veintable_alignhas nothing to do with:align:. Unfortunatelyfigure_alignexists already ... I checked in Lamport's book and he uses location or position. I really think we should use something liketable_loc,table_location,table_position... -
There should be away via a directive to locally override the global positioning default. For example a
.. tableposition::directive. This is LaTeX specific, like.. tabularcolumns.
| .. versionadded:: 1.5 | ||
| ``'figure_align'`` | ||
| Latex figure float alignment, default 'htbp' (here, top, bottom, page). | ||
| LaTeX figure float alignment, default 'htbp' (here, top, bottom, page). |
There was a problem hiding this comment.
I think float alignment creates confusion for LaTeX user. It should be float position (or location as used in the Lamport book).
|
|
||
| .. versionadded:: 1.3 | ||
| ``'table_align'`` | ||
| LaTeX table float alignment, default 'htbp' (here, top, bottom, page). |
| @@ -1,3 +1,11 @@ | |||
| <%- if table.align -%> | |||
There was a problem hiding this comment.
Yes you can't wrap longtable in table
| 'printindex': '\\printindex', | ||
| 'transition': '\n\n\\bigskip\\hrule{}\\bigskip\n\n', | ||
| 'figure_align': 'htbp', | ||
| 'table_align': 'htbp', |
There was a problem hiding this comment.
arguably default could be H for backwards compatibility with former behaviour
| '\\noindent\\begin{tabular}{|\X{30}{100}|\X{70}{100}|}\n' in table) | ||
| assert ('\\hline\n\\end{tabular}\\end{flushleft}\\end{table}' in table) | ||
|
|
||
| # longtable having :align: option (no effect) |
There was a problem hiding this comment.
why no effect ? I have not tested but it should work, except if table is already \linewidth wide.
| (refs: #3379, #3381) | ||
| * #3377: Add support for Docutils 0.13 ``:align:`` option for tables. | ||
| ``'table_align'`` key is added to :confval:`latex_elements` to control the | ||
| table float alignment. |
There was a problem hiding this comment.
float position. Rename table_align to table_pos or table_loc ?
|
To conclude my chaotic verbose review, I am all in favor and I requested changes only to express my agreement with your idea to drop And, I think it is important that user can say: "for this table, use |
|
can you try this, file file and |
|
ok last remark, perhaps tables without caption should not be allowed to float (force H then ?) |
|
once a directive is provided for local override for a table of Attention: About systematic use of |
|
Here is attached a patch on your branch tip which includes the removal of threeparttable, the use of Regarding footnotes, I might have been too alarming, because I had forgotten Sphinx outputs footnotes from tables with separated mark and later footnote text (which by the way makes hyperlinks impossible). The main issue will be that if a table floats to next page, the footnote may be printed before the table. In the root test I use conf.py value of |
|
sorry, patch in previous comment created a problem, I had made a last-minute change but one can note use corrected one: |
|
sorry again I took the git diff at a time I had not quite the sphinx.sty I wanted, here it is. Sorry for spamming I should edit previous comment but if someone uses mail attachement, I feel compelled to provide correct one. edit: I have (more extensive tests needed) working hyperlinked footnotes for table environment. But longtable insists that only the form with footnotemark and footnotetext be used. But the |
|
@jfbu I almost understood what LaTeX's "float" means (maybe). And I noticed it is not important to make tables floatable in LaTeX world. Personally, I'd like to make them like floatable in HTML world. And I had also not know about the advantage of For our purpose, the |
35cd30e to
83a741b
Compare
|
I updated my PR. It simply uses |
|
The "float" in LaTeX means the object is removed from the general flow and either is positioned "here" or moves vertically to the top, bottom, or possibly even to next page or even further hence it is related to HTML position in a way, but has nothing to do with the "float" as in HTML. There is simply no robust existing solution in LaTeX2e for "float" as in HTML (to the best of my knowledge...). The wrapfig package helps, it can position figure or also table with "wraptable" (like threeparttable it knows how to wrap the caption to the asked for width) but it needs manual adjustments. Completely automatized solution with wrapfig package does not exist and also its use has great constraints. E.g. if the object appears in source before a paragraph which extends over a page break, then either the user used lowercase specifier meaning 'put it here' and then the image will overflow bottom of page, and there will be a hole at top of next page; or the user used uppercase specifier allowing the object to "float" in the LaTeX sense, and the object will move not only to next page, but even to next paragraph on next page, which may be a completely unintended context, perhaps even in another section ! See And also wrapfig has big issue of incompatibility with list environments (which may show or not, depending on width of image). Turns out I found an ad hoc hack around it in answering a question on a French forum, but it is not tested in the wild. added: and a wrapfigure environment should not be used before a section title. It must be located before a standard paragraph. This being said, Sphinx uses already This big comment only to make your life more difficult ;-) |
jfbu
left a comment
There was a problem hiding this comment.
LGTM !
quick look at 3.6 style-check failure did not help me see the error: lots of Deprecation warnings, but could not localize "error"
I propose this be merged and later I will make proposal to use something else than the center, ..., environments which add extra vertical spaces compared to current layout.
| (refs: #3379, #3381) | ||
| * #3402: Allow to suppress "download file not readable" warnings using | ||
| :confval:`suppress_warnings`. | ||
| * #3377: Add support for Docutils 0.13 ``:align:`` option for tables |
There was a problem hiding this comment.
the PR seems to be only latex related, thus perhaps this should be said here ? and perhaps say "add partial support..."
| <%- elif table.align in ('left', 'right') -%> | ||
| \begin{flush<%= table.align%>} | ||
| <%- endif -%> | ||
| <% endif -%> |
There was a problem hiding this comment.
memo: this method adds extra vertical spaces due to nature of center, flushleft, flushright environments.
83a741b to
fe2daff
Compare
|
Fixed error and squashed. |
|
And merged. Thank you always :-) |
|
fixed tabulary template at 424041f |
…phinx-doc#3405) also, make "center" the default for short table horizontal alignment (it is already so for longtable)
…3405) also, make "center" the default for short table horizontal alignment (it is already so for longtable)
refs: #3377
@jfbu could you review this please?