10

Pandoc allows referencing images via inline Latex commands. However, it seems it does not work for tables. I'm aware of several workarounds, including manipulating a resulting TeX file manually, but is there a way, for example via inline Latex, to get pandoc to output Latex/PDF/... with automatic table references, like the following (which does not work):

See table \ref{example}.

----------
my  table
--- ------
a   1
b   2
----------
Table \label{example}: An example that does not work.
4
See table \ref{my_table}.

Table: (table title) \label{my_table}

-----------------------
Header1 Header2 Header3
------- ------- -------
item1   item2   item3
-----------------------

The result of the conversion can be generated by using the web interface of pandoc. The LaTeX output is somewhat verbose

See table \ref{my_table}.

\begin{longtable}[c]{@{}lll@{}}
\caption{(table title) \label{my_table}}\tabularnewline
\toprule
\begin{minipage}[b]{0.09\columnwidth}\raggedright\strut
Header1
\strut\end{minipage} &
\begin{minipage}[b]{0.09\columnwidth}\raggedright\strut
Header2
\strut\end{minipage} &
\begin{minipage}[b]{0.09\columnwidth}\raggedright\strut
Header3
\strut\end{minipage}\tabularnewline
\midrule
\endfirsthead
\toprule
\begin{minipage}[b]{0.09\columnwidth}\raggedright\strut
Header1
\strut\end{minipage} &
\begin{minipage}[b]{0.09\columnwidth}\raggedright\strut
Header2
\strut\end{minipage} &
\begin{minipage}[b]{0.09\columnwidth}\raggedright\strut
Header3
\strut\end{minipage}\tabularnewline
\midrule
\endhead
\begin{minipage}[t]{0.09\columnwidth}\raggedright\strut
item1
\strut\end{minipage} &
\begin{minipage}[t]{0.09\columnwidth}\raggedright\strut
item2
\strut\end{minipage} &
\begin{minipage}[t]{0.09\columnwidth}\raggedright\strut
item3
\strut\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

Compare with the ConTeXt output:

See table \ref{my_table}.

\placetable{(table title) \label{my_table}}
\starttable[|lp(0.10\textwidth)|lp(0.10\textwidth)|lp(0.10\textwidth)|]
\HL
\NC Header1
\NC Header2
\NC Header3
\NC\AR
\HL
\NC item1
\NC item2
\NC item3
\NC\AR
\HL
\stoptable

As you can see, in both cases the "table title" is correctly marked as the caption of the generated table.

  • 1
    Welcome to TeX.SX! It would be great if you can extend your answer, for example providing the code for real implementation. – Claudio Fiandrino Jan 20 '14 at 7:44
  • @user44431 Would you mind to elaborate your answer? – pushpen.paul Jul 19 '14 at 16:48
  • @user44431 I hope you do not mind I added the output of Pandoc. Also, try pandoc is very useful for trying the conversion without installing anything. – Bordaigorl Oct 17 '14 at 11:51
3

You can use the pandoc-tablenos filter. Your example would be written

See table @tbl:example.

----------
my  table
--- ------
a   1
b   2
----------

Table: An example that DOES work. {#tbl:example}

The filter is employed using a command-line flag with pandoc:

$ pandoc example.md --filter pandoc-tablenos -o example.pdf

The output format is arbitary: LaTeX/pdf, html, or whatever.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.