I have an org file which I export to LaTeX and then to a PDF document. The problem is I have some long text that exceeds the length of the page. How to wrap it so that it falls into the next line?

First example:

<code goes here> // very long comment that doesn't wrap ........

The comment is very long and exceeds the length of the page, how to make it wrap?

Second example:

| text | text | text                   | text |
| text | text | very long texttt...... | text |

Some cells contain long text which also doesn't wrap, how to make it wrap?

1 Answer 1


From a LaTeX point of view, these are different cases.

In the first case, LaTeX isn't going to wrap -- and it shouldn't! A "verbatim" environment, which is what source-code is set in, respects lines precisely and doesn't break paragraphs, because LaTeX simply can't know where to break them. If you want to wrap the lines, you have to wrap them in the source-code itself.

In the second case, you can use #+ATTR_LATEX to help LaTeX format the table appropriately.

Simplest but least elegant approach: use :align with a p column to specify a width for the problematic column. LaTeX will then wrap that column to the specified width. So this specifies three columns: one aligned left, one a p column with a fixed width of 4cm, and another aligned left.

#+ATTR_LATEX: :align lp{4cm}l

More elegant. Use tabularx and a X column, and LaTeX will then set the column to a length appropriate to enable a table of a fixed overall width. You need to (add-to-list 'org-latex-packages-alist '("" "tabularx")) I think.

#+ATTR_LATEX: :environment tabularx :width \textwidth :align lXl
| column | column with very very very very very overlong text which would flow over | last   |
| column | shorter column                                                           | column |
| column | shorter column                                                           | column |

example output

  • you can also use #+LATEX_HEADER: \usepackage{tabularx} if you only want to add the tabularx package to the local document Commented Jun 19, 2021 at 17:18

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.