1

Suppose that I have 3 types of tables in an org file, A latex table, an org-table, and a html-table. How can we to export these table as html tables when org-exporting to html?

# #+BEGIN_LaTeX
# \begin{table}
# \begin{center}
# \begin{tabular}{l c }
# \hline
#       & Model 1 \\
# \hline
# (Intercept) & $0.06$       \\
#       & $(0.10)$     \\
# x           & $1.02^{***}$ \\
#       & $(0.10)$     \\
# \hline
# R$^2$       & 0.53         \\
# Adj. R$^2$  & 0.53         \\
# Num. obs.   & 100          \\
# RMSE        & 1.05         \\
# \hline
# \multicolumn{2}{l}{\scriptsize{$^{***}p<0.001$, $^{**}p<0.01$, $^*p<0.05$}}
# \end{tabular}
# \caption{Statistical models}
# \label{table:coefficients}
# \end{center}
# \end{table}
# #+END_LaTeX



|-----------+-----|
| groceries | qty |
|-----------+-----|
| apple     |   1 |
| banana    |   5 |
|-----------+-----|




#+BEGIN_HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<table cellspacing="0" align="center" style="border: none;">
<caption align="bottom" style="margin-top:0.3em;">Statistical models</caption>
<tr>
<th style="text-align: left; border-top: 2px solid black; border-bottom: 1px solid black; padding-right: 12px;"></th>
<th style="text-align: left; border-top: 2px solid black; border-bottom: 1px solid black; padding-right: 12px;"><b>Model 1</b></th>
</tr>
<tr>
<td style="padding-right: 12px; border: none;">(Intercept)</td>
<td style="padding-right: 12px; border: none;">-0.10</td>
</tr>
<tr>
<td style="padding-right: 12px; border: none;"></td>
<td style="padding-right: 12px; border: none;">(0.11)</td>
</tr>
<tr>
<td style="padding-right: 12px; border: none;">x</td>
<td style="padding-right: 12px; border: none;">1.33<sup style="vertical-align: 0px;">***</sup></td>
</tr>
<tr>
<td style="padding-right: 12px; border: none;"></td>
<td style="padding-right: 12px; border: none;">(0.11)</td>
</tr>
<tr>
<td style="border-top: 1px solid black;">R<sup style="vertical-align: 0px;">2</sup></td>
<td style="border-top: 1px solid black;">0.60</td>
</tr>
<tr>
<td style="padding-right: 12px; border: none;">Adj. R<sup style="vertical-align: 0px;">2</sup></td>
<td style="padding-right: 12px; border: none;">0.59</td>
</tr>
<tr>
<td style="padding-right: 12px; border: none;">Num. obs.</td>
<td style="padding-right: 12px; border: none;">100</td>
</tr>
<tr>
<td style="border-bottom: 2px solid black;">RMSE</td>
<td style="border-bottom: 2px solid black;">1.07</td>
</tr>
<tr>
<td style="padding-right: 12px; border: none;" colspan="2"><span style="font-size:0.8em"><sup style="vertical-align: 0px;">***</sup>p &lt; 0.001, <sup style="vertical-align: 0px;">**</sup>p &lt; 0.01, <sup style="vertical-align: 0px;">*</sup>p &lt; 0.05</span></td>
</tr>
</table>
#+END_HTML
  • 1
    How do you want LaTeX table to be exported? In case exporting it as an image is OK, then you might be interested in this thread stackoverflow.com/questions/7467870/org-mode-html-export also, look at the by-backend macro which allows you to export the same block (of code) differently, depending on the backend (LaTeX blocks can be also inserted as blocks of code): orgmode.org/worg/org-contrib/babel/languages/… – wvxvw Oct 31 '15 at 16:09
  • @wvxvw sorry for the late reply. That was exactly what i needed. You saved me a lot of work. Thanks. – DJJ Dec 13 '15 at 13:25
0

Thanks to wvxvw for pointing to the answer. I don't deserve any credit, just gathering the information here.

The key thing here is to use the header that will export in latex directly when exporting to latex (C-e-C-l-l).

But it will generate an image first when exporting to html.(C-e-C-h-h)

you need to put the following in your .emacs as well:

(setq org-babel-latex-htlatex "htlatex")
(defmacro by-backend (&rest body)
`(case (if (boundp 'backend) (org-export-backend-name backend) nil) ,@body))

You can have more info about this here

So here is the way to do it.

#+header: :results (by-backend (html "results.png") (t "raw"))
#+header: :results (by-backend (pdf "latex") (t "raw"))
#+BEGIN_SRC latex
\begin{table}
\begin{center}
\begin{tabular}{l c }
\hline
  & Model 1 \\
\hline
(Intercept) & $0.06$       \\
  & $(0.10)$     \\
x           & $1.02^{***}$ \\
  & $(0.10)$     \\
\hline
R$^2$       & 0.53         \\
Adj. R$^2$  & 0.53         \\
Num. obs.   & 100          \\
RMSE        & 1.05         \\
\hline
\multicolumn{2}{l}{\scriptsize{$^{***}p<0.001$, $^{**}p<0.01$, $^*p<0.05$}}
\end{tabular}
\caption{Statistical models}
\label{table:coefficients}
\end{center}
\end{table}
#+END_SRC


|-----------+-----|
| groceries | qty |
|-----------+-----|
| apple     |   1 |
| banana    |   5 |
|-----------+-----|

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.