0

I need a table to be centered with respect to the page. By default it is aligned with the left text border, and being large it exceeds the right page margin:

enter image description here

This is the Org-mode source:

Normal text, Normal text, Normal text, Normal text, Normal text, Normal text, Normal text, Normal text,
Normal text, Normal text, Normal text, Normal text, Normal text, Normal text, Normal text, Normal text,
Normal text, Normal text, Normal text, Normal text, Normal text, Normal text, Normal text, Normal text,

#+ATTR_LATEX: :center
| ABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZ |
|----------------------------|----------------------------|----------------------------|
| ABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZ |
| ABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZ |
| ABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZ |

I tried adding this before my table:

#+BEGIN_LaTeX
  \hspace{-5cm}
#+END_LaTeX

but it had no effect on the table alignment, it only printed the "LaTeX" string.

As an alternative, how can I reduce the font size for the table contents? This, placed before the table, had no effect:

#+begin_export html
<style>
.reveal  td {font-size: 60%;}
</style>
#+end_export

I am interested in both the HTML(5) and PDF exports.

The commands I am using are:

$ emacs file.org --batch -f org-latex-export-to-pdf --kill
$ emacs file.org --batch -f org-html-export-to-html --kill
9
  • 1
    For the alignment, see Table export in LaTeX. For CSS, see CSS support.
    – NickD
    Oct 19, 2023 at 18:46
  • BTW, when I export a table to PDF, it is centered by default - so I'm not sure what you are seeing.
    – NickD
    Oct 19, 2023 at 19:05
  • Also, one question per question please: depending on how you count here, there are either two or four questions. At the very least, you should ask the two questions in your title in separate questions.
    – NickD
    Oct 19, 2023 at 19:08
  • @NickD - I added the LaTeX :center attribute, which has no effect. See the output I added to my question.
    – Pietro
    Oct 23, 2023 at 22:42
  • 1
    That's a different problem, best asked in a different question (although you can refer back to this one for context). Providing a test input file and the screenshot of the results as you did above should go a long way towards eliciting a quick answer from somebody well-versed in CSS.
    – NickD
    Oct 24, 2023 at 15:10

1 Answer 1

1

These are mostly LaTeX problems, not Org mode problems. Org mode knows a tiny bit about LaTeX, so the way to solve the problem is to solve it in LaTeX first and then retrofit the Org mode file to export to the desired LaTeX. In general, the TeX SE site is the proper place for them, but you have to talk about LaTeX there: Org mode is not what they know.

Here are some links to related questions from that site:

I'm sure there are others.


LaTeX/PDF

Here are a couple of methods, based mostly on the above links, to deal with the problems on the Org mode side. But note that I went backwards: once I knew how to do something in LaTeX, I reverse-engineered the solution back to Org mode.

First, the above link shows a method to have the wide table hang into both margins:

\makebox[\textwidth][c]{<table>}

where <table> is a placeholder for the whole LaTeX table. I tested this by having the Org mode exporter produce a .tex file (C-c C-e l l) and then playing around with that file. I added \makebox[\textwidth][c]{ before the LaTeX table and I closed it with } after the table and processed the file through xelatex. The result is that the table is shifted over and starts at the left edge of the page, sticking out into the left margin. However, it is too wide even with that and sticks out into the right margin and to the right edge of the page - and it still doesn't fit: the last XYZ on every row is cut off. It is also very ugly of course.

Nevertheless, I retrofitted it to your Org mode example, and I added two more tables to show the differences: one table with reduced font and one with both methods applied at the same time:

* Test

Normal text, Normal text, Normal text, Normal text, Normal text, Normal text, Normal text, Normal text,
Normal text, Normal text, Normal text, Normal text, Normal text, Normal text, Normal text, Normal text,
Normal text, Normal text, Normal text, Normal text, Normal text, Normal text, Normal text, Normal text,

#+LATEX: \makebox[\textwidth][c]{
#+ATTR_LATEX: :center nil
| ABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZ |
|----------------------------|----------------------------|----------------------------|
| abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz |
| abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz |
| abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz |
#+LATEX: }

#+LATEX: {\tiny
| ABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZ |
|----------------------------|----------------------------|----------------------------|
| abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz |
| abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz |
| abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz |
#+LATEX: }


#+LATEX: {\tiny \makebox[\textwidth][c]{
#+ATTR_LATEX: :center nil
| ABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZ | ABCDEFGHIJKLMNOPQRSTUVWXYZ |
|----------------------------|----------------------------|----------------------------|
| abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz |
| abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz |
| abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz | abcdefghijklmnopqrstuvwxyz |
#+LATEX: }}

The #+LATEX keyword lines add the rest of the line literally to the .tex file at that point, so after the exporter processes the table into LaTeX, the table is surrounded by the \makebox construct (or the {\tiny construct in the second table or both in the third table), exactly as specified in the linked question. The centering is done through the [c] argument of the \makebox macro here.

N.B. in the \makebox cases, I had to turn off the default centering of the table that the LaTeX exporter does by using #+ATTR_LATEX: :center nil: otherwise, I get errors.

HTML

I don't think there is a similar problem with HTML: "pages" in HTML are really whole documents, not like the pages of a book which LaTeX/PDF try to emulate. They are elastic in that (in the absence of other constraints), they will accommodate content as wide as the window (which can be resized) and even wider, by providing scrollbars to allow you to view the off-screen part of the content.

In fact, processing your example through the HTML exporter works fine for me.

[The OP added a comment, describing the problem that he sees with HTML export, but I believe that's a different problem, best dealt with in a different questions.]

1
  • Just what I was looking for. Thank you!
    – Pietro
    Oct 24, 2023 at 16:48

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.