简体   繁体   中英

How to export a org-mode table to LaTeX with the correct placement [h]?

I'm trying to export a table to LaTeX form my org-file which looks like this.

    #+LATEX_HEADER: \usepackage{adjustbox}
    * table test 

    #+begin_table 
    #+LATEX: \caption{my caption}
    label:tab:mylabel
    #+ATTR_LATEX: :placement [h]
    #+LATEX: \centering
    #+LATEX: \adjustbox{max width=\linewidth}{
    #+ATTR_LATEX: :center nil
    |    |                          |
    | id | Question                 |
    |----+--------------------------|
    |    |                          |
    |  1 | Does it export with [h]? |
    #+end_table

I want to get the exported TeX to look like this:

    ... 
    \begin{table}[h]
    \caption{my caption}
    \label{tab:mylabel}
    \centering
    \adjustbox{max width=\linewidth}{
    \begin{tabular}{ll}
     & \\
    id & Question\\
    \hline
     & \\
    1 & Does it export with [h]?\\
    \end{tabular}
    \end{table}
    ...

but only I'm just getting

    ... 
    \begin{table}
    \caption{my caption}
    \label{tab:mylabel}
    \centering
    \adjustbox{max width=\linewidth}{
    \begin{tabular}{ll}
     & \\
    id & Question\\
    \hline
     & \\
    1 & Does it export with [h]?\\
    \end{tabular}
    \end{table}
    ...

using the following versions

GNU Emacs 25.1.1 (x86_64-apple-darwin15.5.0, NS appkit-1404.47 Version 10.11.5 (Build 15F34)) of 2017-01-06

Org mode version 9.0.5 (release_9.0.5-444-g998576 @ ~/git/org-mode/lisp/)

I also tried

#+ATTR_LATEX: :float t :placement [h]

#+ATTR_LATEX: :center nil :float t :placement [h]

#+ATTR_LATEX: :center nil :placement [h]

#+begin_table :placement [h]

#+begin_table :float t :placement [h]

My search on the internet only found some emails from 2010, where org-latex.el existed. Since it is still exists in the documentation I thought it should work some how.

So can anyone help me? Or leak the magic words I have to feed Google with to find my answer?


Thx @Nick, we're on the right way bud sadly not at the end of it.

Well I did not want to brake the parsing, it explains some things. I've got some more requirements and things to explain.

At First some of my tables are a bit wider like this:

   | id | Question                                                                                                                  |
   |----+---------------------------------------------------------------------------------------------------------------------------|
   |  1 | Does it export with [h]?                                                                                                  |
   |  2 | I have some tables witch are very wide so What if you have a really wide table wich needs to be shrinked to the right size |

The Adjustbox package is the first I found that shrinks the whole tavle to the correct width. I tried your suggested tabulrx but it's not shrinking the contents of the table. Without the shrinking most of my tables look wired.

The second Thing, I'm using org-ref . With your version (witch I would prefer when the 2 probs are gone) exports on my box to:

   \caption{\label{tab:org56e3a68}
   My caption}  

I added #+lable: tab:my-label as intended in the documentation. Addet it before and after #+caption: and #+name: but it dos not change anything in the .tex file.

any idea?

I can do everything you want, except the adjustbox stuff with this:

#+BIND: org-latex-prefer-user-labels t
* table test 


#+caption: My caption
#+name:my-label
#+ATTR_LATEX: :placement [h] :center t
|    |                          |
| id | Question                 |
|----+--------------------------|
|    |                          |
|  1 | Does it export with [h]? |

I don't know what \\adjustbox does or how it has to be used and where it has to be placed; however, you can't add #+LATEX: lines in between the #+caption and the table: they apparently break the parsing.

You could add another attribute to the ATTR_LATEX line:

#+ATTR_LATEX: :placement [h] :center t :width \linewidth

but it's not clear that does what you want. Also, I just tested and it does not do anything: that's because the standard environment is tabular which does not take a width argument. The following works:

#+ATTR_LATEX: :environment tabularx :placement [h] :center t :width \linewidth

but you also have to add

#+LATEX_HEADER: \usepackage{tabularx}

at the top of the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM