[Tex/LaTex] Referencing inline-Latex tables in Pandoc Markdown

pandoctables

I have resorted to defining a table using inline-Latex in a Pandoc Markdown document. The reason is that I need to group table rows (using a horizontal line only between certain rows).

I'm trying to get pandoc-tablenos to work with this inline-Latex table, by doing the following:

  • Adding Table: Caption. {#tbl:id} below the table (with a single newline between this text and the last line of the inline Latex) (as described here)
    • Result: the verbatim text Table: Caption. {#tbl:id} is present in the output PDF (below the table) and tbl:id is not recognized as a valid ID

Example Pandoc markdown document with inline Latex table:

# Expressions

Test 123. Table:

\begin{footnotesize}
   \begin{tabular}{ | l l l | } \hline
      \textbf{Expression}        & \textbf{Meaning}            & \textbf{Associativity}     \\ \hline
      \texttt{e1 grouped by e2}  & Add a group to a grouping   & left    \\
      \texttt{e1 where e2}       & Filter a grouping           & left    \\ \hline
   \end{tabular}
\end{footnotesize}

Some more text. *I would like to reference the table here.*

I execute pandoc as follows to build a Latex document:

pandoc --standalone --from markdown -F pandoc-tablenos --pdf-engine=xelatex <input-file>.md -o <output-file>.tex

Best Answer

You need to add the caption and table id within the latex table. Since you are using tabular and no floating environment, you have to use \captionof from the package caption. You can load that in the yaml-header:

---
header-includes: \usepackage{caption}
---

# Expressions

Test 123. Table:

\begin{footnotesize}
  \captionof{table}{A \LaTeX-table. \label{tbl:latex}}
  \begin{tabular}{ | l l l | } \hline
    \textbf{Expression}        & \textbf{Meaning}            & \textbf{Associativity} \\ \hline
    \texttt{e1 grouped by e2}  & Add a group to a grouping   & left                   \\
    \texttt{e1 where e2}       & Filter a grouping           & left                   \\ \hline
  \end{tabular}
\end{footnotesize}

Some more text. See table @tbl:latex

enter image description here

You can ignore the warning:

pandoc-tablenos: Bad reference: @tbl:latex.

It just means, that you haven't defined the label in pandoc-tablenos-syntax

Related Question