Wandmalfarbe / pandoc-latex-template

A pandoc LaTeX template to convert markdown files to PDF or LaTeX.
BSD 3-Clause "New" or "Revised" License
6.09k stars 959 forks source link

How to ref a table #277

Closed sebpardo closed 2 years ago

sebpardo commented 2 years ago

The question on how to reference a figure has already been answered here, but the answer doesn't fully apply for tables: https://github.com/Wandmalfarbe/pandoc-latex-template/issues/189

Referencing a table with \label{} and \ref{} doesn't seem as straightforward given there is no obvious table object to label inside of, as is the case for figures. Is there a way to do this?

Wandmalfarbe commented 2 years ago

You may want to look at https://github.com/lierdakil/pandoc-crossref. I vaguely remember that one should be able to reference tables with this filter.

You could also use raw LaTeX with table captions (https://pandoc.org/MANUAL.html#extension-table_captions)

This is untested:

# Some Heading

There will be table \ref{mylabel}. 
Some Paragraph here.

Table: This is the table caption \label{mylabel}

  Right     Left     Center     Default
-------     ------ ----------   -------
     12     12        12            12
    123     123       123          123
      1     1          1             1
sebpardo commented 2 years ago

Thank you @Wandmalfarbe. Just tried it and can confirm that using the table_captions pandoc extension and placing the \label{} within the caption paragraph does the trick.