This is a sample table in Markdown for Pandoc.
Simple tables look like this:
Right Left Center Default
------- ------ ---------- -------
12 12 12 12
123 123 123 123
1 1 1 1
Table: Demonstration of simple table syntax.
It does not add borders unfortunately.
I might code it as an HTML table, but in this case it will not work in LaTeX.
How can I make a table with borders working both with LaTeX and HTML output?
If Pandoc can't do the job, is there a similar tool which is able to?
Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx.
You can use the program pandoc on the SCF Linux and Mac machines (via the terminal window) to convert from formats such as HTML, LaTeX and Markdown to formats such as HTML, LaTeX, Word, OpenOffice, and PDF, among others.
The default LaTeX template of Pandoc can be found at https://github.com/jgm/pandoc/tree/master/data/templates (named default.
You can do it with Pandoc. But it takes a little bit of more effort.
You have to take advantage of the following facts:
Pandoc can recognize raw LaTeX snippets embedded in Markdown [1]. If the target output format is LaTeX or PDF, it will pass these snippets unchanged into the target document.
So if you know how to write a good looking table in LaTeX, embed it with your Markdown.
For HTML output, this LaTeX table code will be ignored however. That's not a problem, because...
Pandoc can recogniz raw HTML snippets embedded in Markdown [1]. If the target output format is HTML, it will pass these snippets unchanged into the target document.
So if you know how to write a good looking table in HML, embed it with your Markdown.
For LaTeX/PDF output, this HTML table code will be ignored however. That's not a problem, because...
Pandoc can recognize raw LaTeX snippets embedded in Markdown [1].... (aaahhh!, we had that already. See no. 1.
above... :)
pandoc
interactively in the terminal windowHere is another trick.
If you do not know how to start with learning LaTeX, Pandoc can teach you some. Because you can use Pandoc interactively.
For LaTeX output:
It goes like this:
pandoc -t latex
.[RETURN]
.[RETURN]
one more time to be on a newline.[CTRL]+[D]
.See here:
$ pandoc -t latex [RETURN]
Right Left Center Default
------- ------ ---------- -------
12 12 12 12
123 123 123 123
1 1 1 1
Table: Demonstration of simple table syntax.
^D
To be very honest with you: I didn't type the Markdown table.
I cheated.
I copied it from your question and pasted it into the terminal.
The last [^D]
you see is when I hit [CTRL]+[D]
.
This is what appeared in the terminal window then:
\begin{longtable}[c]{@{}rlcl@{}}
\caption{Demonstration of simple table syntax.}\tabularnewline
\toprule
Right & Left & Center & Default\tabularnewline
\midrule
\endfirsthead
\toprule
Right & Left & Center & Default\tabularnewline
\midrule
\endhead
12 & 12 & 12 & 12\tabularnewline
123 & 123 & 123 & 123\tabularnewline
1 & 1 & 1 & 1\tabularnewline
\bottomrule
\end{longtable}
This is the default LaTeX table code generated by LaTeX from the Markdown input.
Now you can google for some methods (if you are not a LaTeX expert yet) to pimp that code in order to make the table looking nicer. The heavy-lifting is already done. (And if you are a LaTeX expert: it still is nice to not need to do the heavy-lifting yourself, isn't it?)
For HTML output:
Of course you can do the very same to output the HTML code of a table as Pandoc would generate it. Look:
$ pandoc -t html [RETURN]
Right Left Center Default
------- ------ ---------- -------
12 12 12 12
123 123 123 123
1 1 1 1
Table: Demonstration of simple table syntax.
^D
<table>
<caption>Demonstration of simple table syntax.</caption>
<thead>
<tr class="header">
<th align="right">Right</th>
<th align="left">Left</th>
<th align="center">Center</th>
<th align="left">Default</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="right">12</td>
<td align="left">12</td>
<td align="center">12</td>
<td align="left">12</td>
</tr>
<tr class="even">
<td align="right">123</td>
<td align="left">123</td>
<td align="center">123</td>
<td align="left">123</td>
</tr>
<tr class="odd">
<td align="right">1</td>
<td align="left">1</td>
<td align="center">1</td>
<td align="left">1</td>
</tr>
</tbody>
</table>
Isn't that nice?
[1] You may need to tell Pandoc that you want to use some of its extensions when processing the Markdown input: pandoc --from=markdown+raw_html+raw_tex+...
, just in case it doesn't work from its default settings...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With