6

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
#+LATEX_HEADER: \usepackage{graphicx}


#+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
#+LATEX_HEADER: \usepackage{graphicx}
#+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
#+LATEX_HEADER: \usepackage{graphicx}
#+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
#+LATEX_HEADER: \usepackage{graphicx}
#+LATEX_HEADER: \usepackage{adjustbox}    
#+begin_src latex :exports results :results latex
\begin{table}
  \caption{a table that scales to the linewidth}
  \centering
  \begin{adjustbox}{width=\textwidth}
    \begin{tabular}{ll}
      A & 1\\
      B & 2\\
    \end{tabular}
  \end{adjustbox}
  \label{tab:scaled}
\end{table}
#+end_src

3 Answers 3

7

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}
#+LATEX: \adjustbox{max width=\linewidth}{
#+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.

2

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"

1
  • Note that this solution also needs #+LATEX_HEADER: \usepackage{tabularx} Commented Jun 30, 2023 at 13:17
0

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   
2
  • 1
    Please elaborate. How does this answer the question? What "file" are you talking about?
    – Drew
    Commented Aug 22, 2020 at 18:14
  • 1
    Sorry for bad description, I just want to share success codes.
    – Billy Jin
    Commented Feb 7, 2021 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.