3
votes

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?

1
It should be :placement [h], not :plcement [h]. Untested.NickD
thx Nick but the typo while entering the question. It is not working with :placement [h]Dings
Did you add the #+BIND directive as described in my answer? That should take care of the org-generated labels. Also, I had no idea that you had modified the question: I get no notifications for that. I just happened to look at the question again and it looked different. So if you want somebody to follow up, please add a comment to the answer with something like :"Please take a look at the modified question".NickD
Also, I believe SO policy is to discourage asking multiple questions in a single post. You should be able to summarize the question in a clear title and that should be the only question in the post. If you have additional questions, you should ask each one in a separate post. At this point, we have strayed far from the placement question that this all started from.NickD
Well Nick again you are right I will post a summarized question and mark this as answered. ThanksDings

1 Answers

5
votes

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.