-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
word_document2 "multiple labels on one line" error #538
Comments
Looks like a regression, but I don't have time to fix it perhaps until 6 months later. If anyone wants to help, a pull request is welcome! |
I'm seeing the same thing with Code:
Result:
|
@Syntanx I have scheduled it in the next release of bookdown, which does not have an ETA yet (perhaps in one month or two). Before I have time to look into it, I guess you have to use two separate |
I guess another option is to pre-combine your images into one figure and render just that figure like shown here: https://sebastiansauer.github.io/two-plots-rmd/
|
@yihui I am also seeing the same problem even though I am calling my plots in separate code chunks. I was trying to include them for a loop and child document. Worked with Main rmarkdnown document has the following code:
The child document has the following example:
|
I was able to workaround this issue by adding a newline between the two plots as follows:
|
The same problem @mdlincoln pointed out occurred, when I tried to insert different images in one chunk or in one The following chunk runs well when the {r scratch, out.width='0.3\\textwidth', fig.ncol = 3, fig.cap='Main caption', fig.subcap = c("subcap1","subcap2", "subcap3"), fig.align='center', fig.show = "hold"}
knitr::include_graphics(c("stimuli/20180708-targets/AgentL/scratch-ha-L.PNG", "stimuli/20180708-targets/AgentL/scratch-ah-L.PNG", "stimuli/20180708-targets/AgentL/scratch-aa-L.PNG")) This is my YAML header for ---
title: "My title"
author: "My name"
date: "`r format(Sys.time(), '%Y年 %B %d日')`"
output:
bookdown::word_document2:
toc: yes
reference_docx: word-styles-reference-01.docx
fig_caption: true
bibliography: myref.bib
always_allow_html: yes
editor_options:
chunk_output_type: console
--- The R chunk above goes well with this YAML for ---
title: "My title"
author: "My name"
date: "`r format(Sys.time(), '%Y年 %B %d日')`"
output:
bookdown::pdf_document2:
latex_engine: lualatex
keep_tex: yes
toc: TRUE
toc_depth: 2
number_sections: TRUE
fig_caption: TRUE
dev: cairo_pdf
extra_dependencies: subfig
#citation_package: natbib
always_allow_html: yes
documentclass: ltjsarticle
header-includes:
- \RequirePackage{luatexja}
- \usepackage{graphicx}
- \usepackage{float}
- \DeclareGraphicsExtensions{.pdf,.PNG}
- \usepackage{luatexja-fontspec}
- \setmainjfont{YuMincho}[UprightFont=YuMincho-Regular,BoldFont=YuMincho-Demibold]
- \setmainfont{TeX Gyre Termes}
- \setsansjfont{YuGothic-Medium}[BoldFont=YuGothic-Bold]
- \setsansfont{TeX Gyre Heros}
- \setlength\parskip{0mm}
- \setlength\parindent{1\Cwd}
- \usepackage[japanese]{babel}
- \captionsjapanese
- \newdimen\bibindent
- \setlength\bibindent{3\Cwd}
#- \newenvironment{hangall}[1]{\hangindent = #1\zw\everypar{\hangindent = #1\zw}}{}
bibliography: myref20180613.bib
#biblio-style: jep.bst
editor_options:
chunk_output_type: console |
Word output does not support fig.subcap and fig.show. I think the following chunk should work
Note that if echo = FALSE, then newlines need to be added in between
|
@h-k-kan {r echo=FALSE, cache=FALSE}
library(knitr)
opts_chunk$set(fig.path = "figure/ja-fig-win-utf8-", fig.height=5, fig.width=5, fig.align="center", echo=FALSE, warning = FALSE, message = FALSE) Therefore, your solution is effective if the global chunk configuration is not set (or if the chunk I added above is ignored when knitting with |
BTW, in fact, I would like to transcribe the code chunks I write in an |
Sorry, I'm new to GitHub, knitr and bookdown, that's why I'm a bit scared with posting to this issue.
Is there a any solution or workaround to make |
Hello, You can use the knit_expand function and a child markdown document. I think that the table numbering is being changed in the print function.
And then in a separate rmd file called: 'table_text.Rmd', you put:
|
Thank you! Didn't know about the |
Hi @yihui!
I noticed you took this off any milestone but hoping it makes its way back on the agenda. It still would be great for dealing with our academic advisors / baby boomers / deep-in-Word luddites! I didn't want to just beg without attempting a PR. Sadly, debugging # .img.cap = function(options, alt = FALSE) {
# cap = options$fig.cap %n% {
# if (is.null(pandoc_to())) sprintf('plot of chunk %s', options$label) else ''
# }
# if (length(cap) == 0) cap = ''
if (pandoc_to() == 'docx' && options$fig.cur != options$fig.cur) cap = ''
# if (is_blank(cap)) return(cap)
# if (alt) return(escape_html(cap))
# paste0(create_label(
# options$fig.lp, options$label,
# if (options$fig.num > 1L && options$fig.show == 'asis') options$fig.cur
# ), cap)
# } Which works for writing out each plot on the same line without throwing op's error. Only the last figure is given the caption and label reference. So markdown output was: ![(\#fig:foo-1)Test Foo](test_files/figure-docx/foo-1.png)<!-- -->![(\#fig:foo-2)Test Foo](test_files/figure-docx/foo-2.png)<!-- -->![(\#fig:foo-3)Test Foo](test_files/figure-docx/foo-3.png) And with that new line would be: ![](test_files/figure-docx/foo-1.png)<!-- -->![](test_files/figure-docx/foo-2.png)<!-- -->![(\#fig:foo-3)Test Foo](test_files/figure-docx/foo-3.png) Thought this would work, but it is still broken so not PR worthy. The figure title underneath is never written when setting: output:
bookdown::word_document2:
fig_caption: true Is the wrong way to hack a fix? Happy to take another stab at it if you have any advice about how you would proceed. |
Should be fixed now. Thanks for the report as well as your attempt to fix it! I also apologize for the long delay. I guess my "R package orbit" is too long now and it is hard to circle back... 😟 Please note that figure captions won't be rendered (even with the fix) unless you use @h-k-kan's |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary. |
I'm encountering an error when trying to render a
word_document2
with more than one figure in a single chunk. Both #249 and #483 suggested this issue had been fixed, and should just result in a warning, but I'm getting it with the latest version of bookdown right now.Sample document:
Building with
bookdown::pdf_document2
works fine. However, I get the following error if trying to useword_document2
:While I expected the warning about
fig.show="hold"
for Word, I did not expect the error.The text was updated successfully, but these errors were encountered: