jupyter-notebookquarto

Can I more easily format long captions for tables and figures in Jupyter Notebooks rendered to PDF with Quarto?


I use Jupyter Notebooks for data analysis, and I would like to use Quarto to couple the research paper PDF to the data analysis. My discipline (economics and finance) uses long figure captions and table captions so figures and tables are fully described and stand alone. I use a comment like the following to generate a table caption:

#| tbl-cap: Counts for All Trades Data with Non-Missing `TRADE_VAR` by Asset and Transaction Types.

This comment works well for short captions. However, it requires left-right scrolling in the code cell to see all the text for 200-word captions. I have tried and failed to get line breaks with | characters. I want the linebreak in my code, not in the output. I want to wrap the markdown code to improve readability in the notebook. Can I more easily format long captions for tables and figures in Jupyter Notebooks rendered to PDF with Quarto? For example, can I store captions in a variable defined elsewhere in the notebook?


Solution

  • Use this if you know you will only being exporting to PDF via LaTeX. You need to use LaTeX \newline to trigger a manual break, but need to escape the first slash as I've done here. Also make sure to put your caption within quotations.

    #| fig-cap: "Counts for All Trades Data with Non-Missing `TRADE_VAR` by Asset \\newline and Transaction Types."
    

    or

    #| tbl-cap: "Counts for All Trades Data with Non-Missing `TRADE_VAR` by Asset \\newline and Transaction Types."
    

    EDIT 10/17/2023: In Response to Clarification from OP

    You can make multi-line options for the caption of the code chunk like this:

    #| fig-cap:
    #|   - "Counts for All Trades Data with Non-Missing `TRADE_VAR`
    #|   by Asset and Transaction Types."
    

    Still resulting in correct caption formatting:

    enter image description here