Menu

#440 longtable labels in the wrong place

closed-fixed
nobody
None
5
2024-04-09
2021-12-21
Erik Hansen
No

The latex2e writer outputs \label{} for tables after \end{longtable}. This is incorrect causing the table referencing to end up with empty reference text rather than the table number. The author of the longtable latex package suggest putting the \label{} inside the caption itself \caption{My caption \label{mylabel}} or inside the table body. The latter option has the added benefit of working for tables without a caption. I've attached a proposed fix.

longtable package documentation can be found at https://mirror.ox.ac.uk/sites/ctan.org/macros/latex/required/tools/longtable.pdf. See page 4 and 5 about the discussion on labeling.

1 Attachments

Discussion

  • Erik Hansen

    Erik Hansen - 2021-12-22

    Btw, I'm a beginner when it comes to Latex. Even though the proposed patch works for my test case, please double check it to ensure it produces valid Latex.

     
  • Günter Milde

    Günter Milde - 2021-12-29
    • status: open --> pending-remind
     
  • Günter Milde

    Günter Milde - 2021-12-29

    Thank you for the report and patch.
    The warning in the source (introduced 2010-02-05 in [r6255])

     other places (beginning, caption) result in LaTeX errors.
    

    makes me hesitating to change the current behaviour. OTOH, it may be outdated.

    Currently standard Docutils does not write \ref macros. How do you get a table number in the document? Can you provide your test file (and info about how it is converted)?

    Did you try your patch with the Docutils test suite? Here, I get FAILED (failures=4, errors=21, skipped=1) and a lot of additional (spurious) labels after longtables.

     

    Related

    Commit: [r6255]

  • Erik Hansen

    Erik Hansen - 2021-12-30

    I've attached the sample table I've used. See tables.rst. I did use the --reference-label ref option to get table numbers in the references. The attached run.sh shows how I've run the tools.

    The standard named references work fine with the \label after the \end{longtable}. When using \ref{} to refer to tables however, no number shows. This only seems possible when the \label{} is moved near the caption or inside table body. See tables_edited.tex for how I'v manually edited the tex file to make it work. That is, if the table has a caption it works. For some reason I haven't been able to place a \label{} inside a table without a caption.

    Haven't run the docutils test suite.

    I guess this whole ticket boils down to how can we get numbered tables references to work?

     
  • Günter Milde

    Günter Milde - 2023-05-25

    Thank you for the additional info, it helped to reproduce the problem.
    Mind, that for references to section numbers with reference-label: ref, you need to activate section numbering by LaTeX (sectnum-xform: False), Docutils-generated section numbers do not show up (cf. the documentation fixes in [r9395]
    With at least one LaTeX-numbered section in the document, a \ref to a table with title/caption (and hence Table number) also works with the \label placed after the table, so setting sectnum-xform to False for the LaTeX writer (or using the somewhat misleading command line option --no-section-numbering) might provide a fast workaround.

    Does the attached patch (against [r9395]) solve the problem?

     

    Related

    Commit: [r9395]

  • Günter Milde

    Günter Milde - 2023-06-22
    • status: pending-remind --> open-fixed
     
  • Günter Milde

    Günter Milde - 2023-06-22

    Fixed in [r9401]. Thank you for reporting.

     

    Related

    Commit: [r9401]

  • Günter Milde

    Günter Milde - 2024-04-09
    • Status: open-fixed --> closed-fixed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.