Menu

#175 Fix alignment of nested tables

None
closed-accepted
nobody
None
5
2021-04-03
2020-10-21
No

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.

1 Attachments

Discussion

  • Günter Milde

    Günter Milde - 2020-10-28

    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.

     
  • John Thorvald Wodder II

    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 \makebox for 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.)

     
  • Günter Milde

    Günter Milde - 2020-11-25
    • status: open --> open-accepted
     
  • Günter Milde

    Günter Milde - 2020-11-25

    Applied in r 8577.
    Thand you for the contribution.

     
  • Günter Milde

    Günter Milde - 2021-04-03
    • status: open-accepted --> closed-accepted
     
  • Günter Milde

    Günter Milde - 2021-04-03

    Fixed in Docutils 0.17.
    Thanks again for your contribution.

     

Log in to post a comment.

MongoDB Logo MongoDB
Gen AI apps are built with MongoDB Atlas
Atlas offers built-in vector search and global availability across 125+ regions. Start building AI apps faster, all in one place.