quarto-dev / quarto-dev/quarto-cli

Wrong alignment for table/figure in `docx` (`fig-align` not working)

Open
#11,589 7 comments 0 reactions 1 assignee View on GitHub

@cscheid is already working on this.

Since Dec 1, 2024.

bug crossref docx triaged-to
Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Description

Alignment is hardcoded by Quarto (not using reference style)

In theory, fig-align is supposed to control caption but it's not the case (maybe related to the cross-reference system refactoring/improvement)

InputOutput
---
title: "Quarto Playground"
format:
  docx:
    reference-doc: centre-caption.docx
    fig-align: center
---

![An image 1]({{< placeholder 600 400 >}}){#fig-placeholder-1}

![An image 2]({{< placeholder 600 400 >}}){#fig-placeholder-2 fig-align="right"}

image

Now, if I remove the alignment hardcoded/added, in addition to get fig-align working, you also get the reference document works by default as one might expect.

function docxParaStyles(align)
  local styles = "<w:pPr>\n"
- local captionAlign = docxAlign(align)
- if captionAlign then
-   styles = styles .. 
-       "<w:jc w:val=\"" .. captionAlign .. "\"/>\n"
- end  
  styles = styles ..
    "<w:spacing w:before=\"200\" />\n" ..
    "<w:pStyle w:val=\"ImageCaption\" />\n" ..
    "</w:pPr>\n"
  return styles
end
InputOutput
---
title: "Quarto Playground"
format:
  docx:
    reference-doc: centre-caption.docx
    fig-align: center
---

![An image 1]({{< placeholder 600 400 >}}){#fig-placeholder-1}

![An image 2]({{< placeholder 600 400 >}}){#fig-placeholder-2 fig-align="right"}

image
---
title: "Quarto Playground"
format:
  docx:
    reference-doc: centre-caption.docx
---

![An image 1]({{< placeholder 600 400 >}}){#fig-placeholder-1}

![An image 2]({{< placeholder 600 400 >}}){#fig-placeholder-2 fig-align="right"}

image

Unfortunately, the code which adds the alignment is needed for table caption to be aligned according to the document level tbl-align.

For short, the current implementation is in conflict with itself resulting in more bad results than good.

Quarto document

---
title: "Quarto Playground"
format:
  docx:
    reference-doc: centre-caption.docx
    tbl-align: left
---

![An image 1]({{< placeholder 600 400 >}}){#fig-placeholder-1}

| A | B | C |
|---|---|---|
| 1 | 2 | 3 |
| 4 | 5 | 6 |

: A table 1 {#tbl-table-1}

![An image 2]({{< placeholder 600 400 >}}){#fig-placeholder-2 fig-align="right"}

| A | B | C |
|---|---|---|
| 1 | 2 | 3 |
| 4 | 5 | 6 |

: A table 2 {#tbl-table-2 tbl-align="right"}

VersionOutput
v1.7 image
  • "Figure 1" should be centred
  • "Figure 2" should be right-aligned
  • "Table 1" is correctly left-aligned
  • "Table 2" should be right-aligned

Results: 1 correct out of 4 cases

No alignment added in `docxDivCaption` image
  • "Figure 1" is correctly centred
  • "Figure 2" is correctly right-aligned
  • "Table 1" should be left-aligned
  • "Table 2" is correctly right-aligned

Results: 3 correct out of 4 cases

Originally posted by @mcanouil in https://github.com/quarto-dev/quarto-cli/discussions/11513#discussioncomment-11428572

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.