# How do I insert resizebox code in org-mode tables when exporting to latex?

I'm trying to figure out how to insert a resize command inside a table environment in org-mode that exports to latex,

Here is my minimal example of raw latex source vs org-mode tables:

#+LATEX_CLASS: article

#+begin_src latex :exports results :results latex
\begin{table}
\caption{a table that scales to the linewidth}
\centering
\resizebox{\linewidth}{!}{%
\begin{tabular}{ll}
A & 1\\
B & 2\\
\end{tabular}}
\label{tab:scaled}
\end{table}
#+end_src


How can I make org-mode tables with a \resizebox{\linewidth}{!}{% } command so that the same result is achieved for the table below? (Or alternatively something else that gives the same result).

#+LATEX_CLASS: article
#+CAPTION: a table that does not scale to the linewidth
#+LABEL: tab:uncaled
| A | 1 |
| B | 2 |


My attempt based on the LaTeX-specific-attributes from org-mode manual

#+LATEX_CLASS: article
#+CAPTION: a table that does not scale to the linewidth
#+ATTR_LATEX: :math-prefix \resizebox{\linewidth}{!}{% :math-suffix }
| A | 1 |
| B | 2 |


However the things I've tried has not worked. In the answer provided to the question on tex.stackechange another alternative is presented, which requires insertion of another environment between table and tabular.

#+LATEX_CLASS: article
#+begin_src latex :exports results :results latex
\begin{table}
\caption{a table that scales to the linewidth}
\centering
\begin{tabular}{ll}
A & 1\\
B & 2\\
\end{tabular}
\label{tab:scaled}
\end{table}
#+end_src


After some investigation i figured out a solution.

Not sure why I didn't see it before or if table export changed in org-mode at some point.

org-mode export tables default as

\begin{center}
\begin{tabular}{lr}
A & 1\\
B & 2\\
\end{tabular}
\end{center}


if the caption and/or label is not specified. Now a table environment can be added around the tabular environment with a caption and label.

#+begin_table
#+LATEX: \caption{Description of table.}
#+LATEX: \label{tab:my-table}
#+ATTR_LATEX: :center nil
| A | 1 |
| B | 2 |
#+LATEX: }
#+end_table


Notice the attr_latex: :center nil. The adjustbox does not play well with \begin{center}...\end{center}.

The specific command I use here only shrinks the table, however any command can be inserted now.

please refer my script that's work

* ttt
**** tt
#+begin_table
#+latex: \resizebox{0.5\columnwidth}{!}{%
|------------------+----------------+--------------------+-------------------+------------------|
|                  | HiFive1        | Arduino 101        | Arduino Zero      | Arduino UNO      |
|------------------+----------------+--------------------+-------------------+------------------|
| Microcontroller  | Freedom E310   | Intel Curie Module | Atmel ATSAMD21518 | Atmel ATmega328p |
| Open Source RTL? | Yes            | No                 | No                | No               |
| CPU speed        | 320+ MHz       | 32 MHz             | 48 MHz            | 16 MHz           |
| CPU ISA          | RISC-VRV32IMAC | X86                | ARMv6-M           | AVR              |
| Bits             | 32 Bit         | 32 Bit             | 32Bit             | 8 Bit            |
| CPU Core         | SiFiceE31      | Intel Quark SE     | ARM Cortex        | AVR              |
| USB              | Micro          | Regular            | 2Micro            | Regular          |
| Flash            | 16384 KB       | 196 KB             | 256 KB            | 32 KB            |
| PWM              | 9              | 4                  | 10                | 6                |
| SRAM             | 16 KB          | 24 KB              | 32 KB             | 2 KB             |
| Digital IO       | 19             | 14                 | 14                | 14               |
| IO Voltage       | 3.3 V and 5V   | 3.3V and 5V        | 3.3 V only        | 5V only          |
| DMIP’s          | 1.61 MHz       | 1.3 MHz            | 0.93 MHz          | 0.30 MHz         |
| DMIP’s          | 3.16 mW        | 0.35 mW            | –                 | 0.10 mW          |
| Total Drystones  | 515.2          | 41.6               | 44.64             | 5                |
|------------------+----------------+--------------------+-------------------+------------------|
#+latex: %
#+latex: }
#+end_table

• Please elaborate. How does this answer the question? What "file" are you talking about? – Drew Aug 22 '20 at 18:14
• Sorry for bad description, I just want to share success codes. – Billy Jin Feb 7 at 15:35

A late reply but may I suggest another solution ? Instead of resizing the table, you may want to split the lines when they exceed a given limit, for example textwidth :

#+caption: Your table
#+ATTR_LATEX: :environment tabularx :width \textwidth :align XX
| A | 1 |
| B | 2 |


Pros : less code ! It also avoids very small, unreadable tables.

Cons : You have to specify the number of columns in the :align flag with "X"es, not with numbers. 4 columns mean ":align XXXX" and not ":align 4"