Witiko / markdown

:notebook_with_decorative_cover: A package for converting and rendering markdown documents in TeX
http://ctan.org/pkg/markdown
LaTeX Project Public License v1.3c
331 stars 31 forks source link

Support for markdown tables #32

Closed AnthonyEbert closed 5 years ago

AnthonyEbert commented 6 years ago

Thank you for providing this package! I tried to insert a markdown table into a latex document, the table below was not rendered.

Letters Numbers
a 1
b 2

Here is the tex file I wrote.

\documentclass{article}

\begin{document}

\begin{markdown}

## A table

| Letters | Numbers |
| ----    | ---     |
|   a     |  1      |
|   b     |  2      |

\end{markdown}

\end{document}

The output came out like this | Letters | Numbers | | —- | — | | a | 1 | | b | 2 | when I ran pdflatex -shell-escape file.tex.

Thanks again

Witiko commented 6 years ago

Hi, the Markdown parser does not support tables at the moment. Here are several workarounds you can use:

Mixing Markdown with LaTeX

\documentclass{article}
\usepackage[hybrid]{markdown}
\begin{document}
\begin{markdown}
# A table
\begin{tabular}{cc}
  Letters & Numbers \\\\ \hline
  a & 1 \\\\
  b & 2
\end{tabular}
\end{markdown}
\end{document}

screenshot_20180310_230344

CSV tables using file transclusion

\documentclass{article}
\usepackage{filecontents}
\usepackage[contentBlocks]{markdown}
\begin{document}
\begin{filecontents*}{table.csv}
Letters,Numbers
a,1
b,2
\end{filecontents*}
\begin{markdown}
# A table
/table.csv (Letters and numbers)
\end{markdown}
\end{document}

screenshot_20180310_230344

dvins commented 5 years ago

Thank you for the work arounds but they do not solve the problem of streaming content, written in Markdown and using tables, into a larger Latex document. Is support for this an impossibility? Is this something that can be accomplished if a few of us sponsor the work?

Witiko commented 5 years ago

Hello @dvins, I agree that the workarounds are imperfect. From the technical viewpoint, tables are completely doable. In fact, I see two ways they can be implemented:

  1. Add table support to jgm/lunamark. Tables are parsed and rendered by us.
  2. Add support for the Pandoc backend. Tables are parsed by the Pandoc backend, we just render the AST produced by Pandoc.

The constraining factor for me is time. There is currently enough open issues for me to have my hands full with just maintaining and documenting the package before the TeX Live 2019 release. A sponsorship would help me find a second contributor specifically to implement table support.

dvins commented 5 years ago

What is the best email to contact you at to discuss sponsorship further? In terms of approach the first is best and preferred so can be leveraged in a system like ShareLaTex as an import library.

Witiko commented 5 years ago

You can reach me at witiko@mail.muni.cz

dvins commented 5 years ago

@Witiko Sent you an email the other night.

Witiko commented 5 years ago

Table support is now available in the master branch and will be published in version 2.8.0 by the end of April. See the following example:

\documentclass{article}
\usepackage[pipeTables, tableCaptions]{markdown}
\begin{document}
\begin{markdown}
| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
|   12  |  12  |    12   |    12  |
|  123  |  123 |   123   |   123  |
|    1  |    1 |     1   |     1  |

  : Demonstration of pipe table syntax.
\end{markdown}
\end{document}
rafaelzemog commented 5 years ago

Hello I have been working with table support but I have two issues:

  1. The tables are misplaced eg. at the top of the page when they must be in the middle of the page.
  2. I only have the horizontal lines displayed in the table nor the vertical ones.
    
    ### Documentos oficiales
    \vspace{1cm}
ID DOCUMENTO DESCRIPCIÓN
DOC-1 Propuesta para el Proyecto Sistema Aéreo No Tripulado de Despegue y aterrizaje Vertical

Table: Documentos oficiales de referencia

Otras publicaciones técnicas, legales y referenciales

\vspace{1cm}

ID DOCUMENTO DESCRIPCIÓN
DOC-2 Manual de Procesos del Sistema de Gestión de Calidad del INIDETAM

Table: Otras publicaciones aplicables



![My oputput](https://user-images.githubusercontent.com/3085858/57186476-c0834b80-6ea5-11e9-9c48-9607fce91fa9.png)
Witiko commented 5 years ago

Hello @rafaelzemog,

let's have a look at the issues you outlined:

  1. The tables are misplaced eg. at the top of the page when they must be in the middle of the page.

You can specify to LaTeX that it should not make tables float:

\usepackage{float}
\makeatletter
\renewcommand*{\fps@table}{H}
\makeatother

Spectacle TJ7808

Alternatively, when you don't specify a caption, the default LaTeX table renderer will also prevent tables from floating:

### Documentos oficiales
| ID DOCUMENTO | DESCRIPCIÓN |
|:------------:|:------------------------------------------------|
| DOC-1        | Propuesta para el Proyecto Sistema Aéreo No Tripulado de Despegue y aterrizaje Vertical |

### Otras publicaciones técnicas, legales y referenciales
| ID DOCUMENTO | DESCRIPCIÓN                                                       |
|:------------:|-------------------------------------------------------------------|
| DOC-2        | Manual de Procesos del Sistema de Gestión de Calidad del INIDETAM |

Spectacle TJ7244

  1. I only have the horizontal lines displayed in the table nor the vertical ones.

Omitting vertical lines is generally prefered in modern typesetting. If you want to add horizontal lines, you will need to modify the default table renderer (or write your own):

\usepackage[pipeTables,tableCaptions]{markdown}
\makeatletter
\def\markdownLaTeXReadAlignments#1{%
  \addto@hook\markdownLaTeXTableAlignment{|}%
  \advance\markdownLaTeXColumnCounter by 1\relax
  \if#1d%
    \addto@hook\markdownLaTeXTableAlignment{l}%
  \else
    \addto@hook\markdownLaTeXTableAlignment{#1}%
  \fi
  \ifnum\markdownLaTeXColumnCounter<\markdownLaTeXColumnTotal\relax\else
    \addto@hook\markdownLaTeXTableAlignment{|}%
    \expandafter\@gobble
  \fi\markdownLaTeXReadAlignments}
\makeatother

Spectacle TJ7808

rafaelzemog commented 5 years ago

Thank you for your support.

awelormro commented 2 years ago
Is the multiline header enabled? First of all, thank you for this tool, runs amazingly in neovim with Arch, but in this case, I'm trying to make a table similar to this ` Año Total Carbón Derivados Gas Natural Energía Energía Porcentaje del petróleo nuclear renovable de renovable
2000 420 97 153 86.8 28.3 54.7 13.00
2005 481 125 168 98.8 30.2 59.4 12.30
2010 539 153 173 115 30.1 68.2 12.60
2015 572 161 182 123 28.1 77.8 13.60
2016 576 156 184 127 28.5 80.6 14.00
2017 585 158 186 130 28.8 81.1 13.90

`

Is this possible or shall I need to make anything different?

Witiko commented 2 years ago

@awelormro This is not possible with the pipeTables syntax extension. As you can see, GitHub does not render your table either.

fenggeorgeyu commented 1 year ago

For the pipeline table in latex, is there any way the table caption can be on top of the table instead of under the table? Thanks for helping.

Witiko commented 1 year ago

@fenggeorgeyu You can use LaTeX packages float and caption to control the placement and spacing of captions:

\documentclass{article}
\usepackage[pipeTables,tableCaptions]{markdown}
\usepackage{float,caption}
\begin{document}

\floatstyle{plain}  % Setup float package to always put captions below tables
\restylefloat{table}
\captionsetup[table]{position=below}  % Setup caption package to place \abovetopsep between caption and table
\begin{markdown}

| Here is a header |
|------------------|
| Here is a row    |

: Here is a caption

\end{markdown}

\floatstyle{plaintop}  % Setup float package to always put captions above tables
\restylefloat{table}
\captionsetup[table]{position=above}  % Setup caption package to place \abovetopsep between caption and table
\begin{markdown}

| Here is a header |
|------------------|
| Here is a row    |

: Here is a caption

\end{markdown}

\end{document}

scrot

Alternatively, you could redefine the table renderer in any way you see fit. This is more difficult, but you would not have to rely on LaTeX packages table and float. Here is the default definition of the table renderer in LaTeX.

Hope this helps! Please, use Discussions for future Q&A on this topic and any other topic.

fenggeorgeyu commented 1 year ago

Your solution of using LaTeX packages float and caption works great! I will look into the table render option later on. Thanks for the great help! Definitely, I will ask questions in Discussions in the future. Thanks again!