I am generating PDF documentation from rst files using sphinx, latex and latexpdf. The rst files include wide tables with long table titles using "csv-table". I would like the table title to print in one long line instead of wrapping. How can I set the width of the table title to match the width of the table and control the title alignment (e.g. left vs center)?

Note - the width of the table is fills the width of the pdf output page as desired. The width and alignment of the table title is the issue.

I've tried searching sphinx documentation and online for ways to update the rst files or the conf.py file. Not sure where to look next.

Here is what I have in the rst file:

.. csv-table:: Very long table title that is shorter than the width of the table
    :file: filename.csv
    :header-rows: 1
    :class: longtable
    :widths: 30 70

Note, my tex file already has the following line:

\caption{Very long table title that is shorter than the width of the table
  • 5
    Welcome :) could you provide some code showing what you have tried so far? – Superuser27 Mar 26 '19 at 15:46
  • Ok, but what are you trying to do in your tex file? :) – Superuser27 Mar 26 '19 at 18:24
  • Hi - that snippet I have in the original comment is what I actually have in the rst file. filename.csv has: ``` Name,Description NameA, This is a description of NameA. NameB, This is a description of NameB. ``` I am not sure where to look next. I have a conf.py file with: ``` latex_elements = {} ``` This seemed like it might be a place to set the table title character width, but I don't see any way to do that in the documentation for latex_elements under: sphinx-doc.org/en/1.8/usage/configuration.html I am using Sphinx version 1.8. – AJK Mar 26 '19 at 18:31
  • thank you...let me find the tex file and research how to use it. I will come back if I figure it out or have more questions. – AJK Mar 26 '19 at 18:32

Thank you for the pointer to the tex file! The wrapping issue was fixed after I added the following line in the tex file and then regenerated the pdf files:


However, my tex file is generated in my build process, so that couldn’t be my final fix.

Adding the following line in my conf.py file fixed the wrapping issue. After I made this update in conf.py, the tex file that is generated and used when I run latex & latexpdf includes “\usepackage{caption}”.

 latex_elements = {
    'preamble': '\\usepackage{caption}'

Regarding the alignment of the table caption (title), I found the following duplicate question whose answer works for me too: Table caption should be left aligned

So now, all of my question has been answered. Thank you for the pointers.

| improve this answer | |
  • hm, is this an answer? it seems that only clarify your question, so it should be moved there. – Zarko Mar 26 '19 at 23:01
  • Hi Zarko - yes, that answer fixed the issue for me. (After I updated my conf.py file as described in the answer above, the table caption no longer wraps.) The note I had in the answer was clarification, so I moved it from the answer to the question. That note was something I discovered, not changed, after following up on Superuser27's comment. Thank you both for the responses. – AJK Mar 27 '19 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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