Currently, the (Xe)LaTeX writers start tables with r'\begin{%s}[%s]' % (self.get_latex_type(), align), where the horizontal alignment is set via an optional "pos" option to the table environment. However, setting the horizontal alignment in this way only works for longtable and longtable*; for the tabular environment (used for tables nested within tables), the "pos" argument is used to set the vertical alignment only, and applying [l], [c], or [r] to a tabular does nothing, leaving it aligned with the surrounding text. The correct way to set a tabular's horizontal alignment is by enclosing it in a flushleft, center, or flushright environment as appropriate, and the attached patch updates the writers' treatment of non-longtable tables to do just that.
Thank you for the report and patch.
Unfortunately, the fix with environments adds much vertical space which is unfortunate
in the case of nested tables.
This can be fixed using \raggedright, \centering, and \raggedleft instead. The latex writer has already the "insert_align_declaration" function for this purpose (used in visit_line_block).
However, it must be ensured that this does not affect the following text:
https://tex.stackexchange.com/questions/208898/how-to-align-text-to-right-without-adding-additional-vertical-spacing#208899
To facilitate a visual check of the LaTeX output, I added a section to the "latex-cornercases" functional test sample in revision 8570. Feel free to play with it and use it may replace the latex-writer test case.
I tried setting tabular alignment with
{\raggedleft ... \par}as suggested, but that ended up producing too much vertical whitespace below the tabular when there was nothing else in the outer cell. However, aligning with\noindent\makebox[\linewidth][$ALIGN]{...}as is done for images does not produce excessive whitespace, so I have written a new patch that uses this method to align nested tables. (I choose to use\makeboxfor all alignments both for simplicity and because\noindent{\hfill ...}as is done for images adds a little bit of extra horizontal whitespace on the side that I don't like.)Applied in r 8577.
Thand you for the contribution.
Fixed in Docutils 0.17.
Thanks again for your contribution.