Skip to content

Cannot insert images to flextable in docx; image syntaxes parsed by ftExtra::colformat_md() cannot render in pdf #14220

@ErwinTATP

Description

@ErwinTATP

I have:

  • searched the issue tracker for similar issues
  • installed the latest version of Quarto CLI
  • formatted my issue following the Bug Reports guide

Bug description

I tried to insert images into flextable cells. I've tried two approaches:

  1. Insert into dataframe with markdown syntax(![](path/to/image.png)), which was parsed by ftExtra::colformat_md()
  2. Insert as a flextable object via flextable::as_image()

For docx, neither of the approaches worked, only producing a strange text placeholder at where the images were supposed to be. Other markdown features like bold and subscripts had been parsed and rendered correctly.

For pdf, adding the image syntax would cause fatal error and stop pdf rendering. If I remove the markdown image syntax from the table, the pdf would render as expected.

Steps to reproduce

sandbox.qmd:

---
format:
  docx:
    toc: false
  pdf:
    toc: false

execute:
  echo: false
  error: false
  warning: false
---
```{r}
#| tbl-cap: "flextable with **Markdown**"
#| label: tbl-tables

library(tidyverse)
library(flextable)
library(ftExtra)

data.frame(
  R = "![](/Library/Frameworks/R.framework/Resources/doc/html/logo.jpg)",
  img = "",
  markdown = "^This^ ~is~ **markdown**",
  stringsAsFactors = FALSE
) |>
  flextable() |>
  colformat_md() |>
  compose(
    j = "img",
    value = as_paragraph(as_image(src = file.path(R.home("doc"), "html", "logo.jpg"), width = 1, height = 1))
  )
```

Actual behavior

quarto render sandbox.qmd

processing file: sandbox.qmd
1/3             
2/3 [tbl-tables]
3/3             
output file: sandbox.knit.md

pandoc 
  to: docx
  output-file: sandbox.docx
  default-image-extension: png
  toc: false
  variables: {}
  
processing file: sandbox.qmd
1/3             
2/3 [tbl-tables]
3/3             
output file: sandbox.knit.md

pandoc 
  to: latex
  output-file: sandbox.tex
  standalone: true
  pdf-engine: lualatex
  variables:
    graphics: true
    tables: true
  default-image-extension: pdf
  toc: false
  
metadata
  documentclass: scrartcl
  classoption:
    - DIV=11
    - numbers=noendperiod
  papersize: letter
  header-includes:
    - \KOMAoption{captions}{tableheading}
  block-headings: true
  
Rendering PDF
running lualatex - 1
  This is LuaHBTeX, Version 1.24.0 (TeX Live 2026) 
   restricted system commands enabled.
  
updating tlmgr

updating existing packages
ERROR: 
compilation failed- error
Missing number, treated as zero.
<to be read again> 
N
l.216 ...sandbox_files/figure-pdf/tbl-tables-1.png}}
                                                   & \multicolumn{1}{>{\ragg...

see sandbox.log for more information.
WARN: Error encountered when rendering files

docx output:

Table output in docx with some markdown formatting. Images were supposed to be in the cells, but they have been wrongly replaced by text placeholders reading 'Shape...'

pdf output:

pdf failed to render. sandbox.aux, sandbox.log, sandbox.tex files and the sandbox_files folders are all there.

The sandbox.tex had the following lines that caused error:

\multicolumn{1}{>{\raggedright}m{\dimexpr 0.75in+0\tabcolsep}}{\includegraphics[width=NAin, height=NAin]{sandbox_files/figure-pdf/tbl-tables-1.png}} & \multicolumn{1}{>{\raggedright}m{\dimexpr 0.75in+0\tabcolsep}}{\includegraphics[width=1in, height=1in]{sandbox_files/figure-pdf/tbl-tables-2.png}} & \multicolumn{1}{>{\raggedright}m{\dimexpr 0.75in+0\tabcolsep}}{\textcolor[HTML]{000000}{\fontsize{11}{11}\selectfont{\global\setmainfont{Helvetica}{\textsuperscript{This}}}}\textcolor[HTML]{000000}{\fontsize{11}{11}\selectfont{\global\setmainfont{Helvetica}{\ }}}\textcolor[HTML]{000000}{\fontsize{11}{11}\selectfont{\global\setmainfont{Helvetica}{\textsubscript{is}}}}\textcolor[HTML]{000000}{\fontsize{11}{11}\selectfont{\global\setmainfont{Helvetica}{\ }}}\textcolor[HTML]{000000}{\fontsize{11}{11}\selectfont{\global\setmainfont{Helvetica}{\textbf{markdown}}}}} \\

Expected behavior

The image should be rendered within the cell:

Desired table output in docx. The jpeg logo of R language is shown correctly in the cell

The example above is provided in documents of ftExtra package.

I've checked that the image file /Library/Frameworks/R.framework/Resources/doc/html/logo.jpg does exist on my computer.

Your environment

  • OS: Mac OS X Tahoe (26.3.1) ARM64
  • IDE: NVIM 0.11.6
  • Office: LibreOffice 26.2.1.2

Quarto check output

quarto check

Quarto 1.8.27
[✓] Checking environment information...
      Quarto cache location: /Users/[username]/Library/Caches/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.6.3: OK
      Dart Sass version 1.87.0: OK
      Deno version 2.3.1: OK
      Typst version 0.13.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.8.27
      Path: /Applications/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: v2026.03.02
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/[username]/Library/TinyTeX/bin/universal-darwin
      Version: 2026

[✓] Checking Chrome Headless....................OK
      Chrome:  (not detected)

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

[✓] Checking Python 3 installation....OK
      Version: 3.13.12
      Path: /Users/[username]/global_venv/.venv/bin/python3
      Jupyter: 5.9.1
      Kernels: ir, rkernel, ark, python3

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

[✓] Checking R installation...........OK
      Version: 4.5.2
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library
      knitr: 1.51
      rmarkdown: 2.30

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtablesIssues with Tables including the gt integrationthird-partyIssues involving interaction with a third-party library

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions