quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.55k stars 293 forks source link

Customizing Table style in Word Output via Quarto #10066

Open hasibagen opened 2 weeks ago

hasibagen commented 2 weeks ago

Bug description

I encountered an issue where a table generated with pd.to_markdown in Jupyter Lab loses its borders when exported to Word using Quarto. The borders appear correctly in the PDF output.

How can I resolve the issue of missing table borders in the Word output? How can I adjust the table style, such as center alignment, when generating Word documents? I am aware of the capabilities of knitr in R Markdown but need a solution entirely in Python.

Thank you for your assistance.

Steps to reproduce

import seaborn as sns from IPython.display import Markdown, display mpg = sns.load_dataset("mpg").head(3) display(Markdown(mpg.to_markdown(index = False)))

Default Left Right Center
12 12 12 12
123 123 123 123
1 1 1 1

: Demonstration of pipe table syntax

bug_demo.zip

Expected behavior

Expected: The table should have borders in both PDF and Word outputs.

Actual behavior

Actual: The table has borders in the PDF output but lacks borders in the Word output.

Your environment

Operating System: Ubuntu 22.04 Jupyter Lab Version: IPython : 8.18.1 ipykernel : 6.29.4 ipywidgets : 8.1.2 jupyter_client : 8.6.1 jupyter_core : 5.7.2 jupyter_server : 2.14.0 jupyterlab : 4.1.8 nbclient : 0.10.0 nbconvert : 7.16.4 nbformat : 5.10.4 notebook : 7.1.3 qtconsole : 5.5.2 traitlets : 5.14.3

Quarto check output

Quarto 1.5.45
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.5.45
      Path: /opt/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: v2024.06
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /home/jade/.TinyTeX/bin/x86_64-linux
      Version: 2024

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.9.6 (Conda)
      Path: /home/jade/anaconda3/envs/fnirs/bin/python
      Jupyter: 5.7.2
      Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.4.0
      Path: /usr/lib/R
      LibPaths:
        - /home/jade/R/x86_64-pc-linux-gnu-library/4.4
        - /usr/local/lib/R/site-library
        - /usr/lib/R/site-library
        - /usr/lib/R/library
      knitr: 1.46
      rmarkdown: 2.26

[✓] Checking Knitr engine render......OK
cderv commented 2 weeks ago

The docx you shared has some borders image

PDF has more image

But this is due to which Table is used in word document and how it is configured. You can change the default, but changing the style using a reference document. https://quarto.org/docs/output-formats/ms-word-templates.html

I see that Style in your docx you shared image

Hope it helps

hasibagen commented 2 weeks ago

The docx you shared has some borders image

PDF has more image

But this is due to which Table is used in word document and how it is configured. You can change the default, but changing the style using a reference document. https://quarto.org/docs/output-formats/ms-word-templates.html

I see that Style in your docx you shared image

Hope it helps

Thank you very much for your suggestion. I have modified the table style in the word template as you said, using libreoffice. However, after using the template to generate word, the exported word table is still dotted. I would like to ask why this is? I also tried to use word and wps to modify the word template, but it seems that the result is the same, there is no table border. This is my modified code and word template. Looking forward to your reply.

with_word_temple.zip

cderv commented 2 weeks ago

A few things:

It works for me when I do this (though I am on Windows with Word to use docx files)

Changing default Table styles in something that Pandoc still needs to support for Quarto to be able to benefit from it

So for now, one need to follow exactly how reference doc template works with Pandoc to be able to customize a Quarto docx output

Hope it helps