rstudio / bookdown

Authoring Books and Technical Documents with R Markdown
https://pkgs.rstudio.com/bookdown/
GNU General Public License v3.0
3.78k stars 1.27k forks source link

Chunck option "fig.fullwidth=TRUE" does not produce full-width figure #312

Closed j-bot1 closed 3 years ago

j-bot1 commented 7 years ago

First of all, thank you for creating and maintaining something amazing.

In the bookdown book, It says to refer to the tufte package documentation for special chunk options related to the tufte style. after some googling, it seems that the chunck option "fig.fullwidth" is used to create full width fiigures that span both columns of the tufte style.

When using "tufte_html_book" as output, chunk option "fig.fullwidth=TRUE" does not result in a full width figure. what am I doing wrong?

Simple example code below.

---
title: "A Book"
author: "Frida Gomam"
site: bookdown::bookdown_site
documentclass: book
output:
  bookdown::tufte_html_book
---

# Testing figure placement

Full width figure.

```{r fig.fullwidth=TRUE}
x <- rnorm(1000)
y <- rnorm(1000)

par(mfrow=c(1,2))
plot(x)
plot(y)
```  
Margin figure. 
```{r fig.margin = TRUE}
plot(y)
```
yihui commented 7 years ago

That is likely to be a bug, but I don't have time to fix it right now. Sorry. If you want to dive into the source code and fix it, a pull request will be very much appreciated!

puterleat commented 7 years ago

Don't you need a comma after the r in your chunk definition?

yihui commented 7 years ago

@puterleat No, the comma after r is optional.

yihui commented 6 years ago

Just for the record: https://stackoverflow.com/q/47501383/559676

tomhopper commented 6 years ago

Comparing the .tex output for the example in StackOverflow from RMarkdown and LyX, the LyX output is not wrapping (\includegraphics{}) in a figure* environment.

Snippet of TeX file output from RMarkdown:

\begin{figure*}
\includegraphics{fullwidth_test2_tufte_files/figure-latex/example3-1} \end{figure*}

The equivalent snippet of TeX from LyX's "Export to PDF (pdflatex)":

\end{kframe}
\includegraphics[width=\maxwidth]{figure/example3-1} 

\end{knitrout}

The files from LyX (test_fullwidth.*) and RMarkdown (fullwidth_test2_tuft.tex) are attached. the ".txt" extension will have to be removed after downloading.

test_fullwidth.lyx.txt test_fullwidth.tex.txt fullwidth_test2_tufte.tex.txt

cderv commented 3 years ago

This issue is now quite old and I can't reproduce with last version of packages.

Figure is fullwidth (body + margin) using this code

---
title: "A Book"
author: "Frida Gomam"
site: bookdown::bookdown_site
documentclass: book
output:
  bookdown::tufte_book2: default
  bookdown::tufte_html_book: default
---

# Testing figure placement

Full width figure.

```{r fig.fullwidth=TRUE}
x <- rnorm(1000)
y <- rnorm(1000)

par(mfrow=c(1,2))
plot(x)
plot(y)

Margin figure.

plot(y)
jtrakk commented 3 years ago

I can reproduce it. At least, I get a result that isn't what I want: I was expecting the figure to go all the way to both sides of the screen. Instead it only has the same width as the text does.

If there is a workaround for showing large figures that would be helpful to me.

image

> packageVersion("knitr")
[1] '1.30'
> packageVersion("tufte")
[1] '0.9'
---
title: Title
author: Author name
output:
  tufte::tufte_handout: default
  tufte::tufte_html: default
---

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam mollis erat nec augue dignissim, at fringilla risus dictum. Aliquam venenatis semper ligula nec posuere. Pellentesque dictum quam nec neque varius consequat. Cras consequat est non faucibus convallis. Ut faucibus tempus augue et sagittis. Maecenas nibh lacus, lacinia ac pulvinar aliquet, suscipit in nulla. Aenean nec sapien nec nulla ultrices egestas sit amet nec erat. In finibus turpis velit, eu gravida risus porta nec. In congue, purus quis congue varius, tellus ipsum tempor est, in cursus tortor mauris sit amet odio. Pellentesque id tellus lacinia, molestie magna id, tincidunt libero. Etiam aliquam lorem in ultricies scelerisque. Vestibulum nulla lectus, tempus eu gravida at, vehicula eget eros.

Proin tempor pulvinar fringilla. Morbi elementum sagittis enim sit amet ullamcorper. Nulla sodales diam non nisi tempus, non porta sapien fermentum. Nulla facilisi. Vestibulum semper molestie fringilla. Etiam sed augue vitae sapien auctor viverra. Aliquam sapien magna, ornare a consectetur in, maximus ac ante. Nunc nulla nulla, rhoncus ut consequat ut, pellentesque quis libero. Phasellus hendrerit ipsum ac sollicitudin aliquam. Morbi sed nibh nec nisi ultricies faucibus non vel diam. Suspendisse sollicitudin blandit diam, eget ultrices nisl egestas eget. Curabitur pellentesque vulputate vehicula.

Aenean id augue erat. Aenean non mauris dolor. Nunc pretium lacus eget nisi faucibus, eget aliquam mauris scelerisque. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Mauris eleifend lacinia massa, vitae mattis velit ultricies in. Nulla sed erat ac ante maximus eleifend et id turpis. Nam aliquam sollicitudin urna ut volutpat. Quisque placerat accumsan libero, at elementum lacus consectetur ut.

In ex nibh, mattis in ex in, sodales efficitur massa. Mauris risus nisl, molestie vel scelerisque vitae, tempus ut felis. Integer a malesuada dui, non semper leo. Nulla placerat purus et pharetra consectetur. Nulla vel efficitur lorem. Vivamus nec magna eu purus bibendum efficitur. Quisque euismod risus tellus. Donec elementum eros vitae venenatis venenatis. Vestibulum ullamcorper, odio at hendrerit vestibulum, metus libero ornare eros, non facilisis tortor mauris sed purus. Proin ut massa facilisis, dignissim odio sit amet, vestibulum lectus.

Nulla pulvinar pharetra porta. Cras fringilla libero in lectus porttitor vehicula. Proin faucibus posuere est. Vivamus lacinia consectetur lacus, ut dignissim nisl vehicula eu. Mauris sagittis quam interdum orci efficitur, eget finibus risus sodales. Nam laoreet nulla at consequat dapibus. Aenean non nunc orci. Praesent ornare dapibus odio, eu pellentesque orci dignissim nec. Donec euismod massa turpis, at porta lorem pharetra at. Proin orci arcu, tristique vitae sollicitudin eget, congue at purus. Phasellus ut mi nulla. Donec eu maximus velit. Cras quis diam lobortis, tempus erat et, tincidunt nisl.

```{r, fig.width=30, fig.height=30, fig.fullwidth=TRUE}
library(ggplot2)
ggplot(diamonds) + geom_point(aes(carat, price, color=color))

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam mollis erat nec augue dignissim, at fringilla risus dictum. Aliquam venenatis semper ligula nec posuere. Pellentesque dictum quam nec neque varius consequat. Cras consequat est non faucibus convallis. Ut faucibus tempus augue et sagittis. Maecenas nibh lacus, lacinia ac pulvinar aliquet, suscipit in nulla. Aenean nec sapien nec nulla ultrices egestas sit amet nec erat. In finibus turpis velit, eu gravida risus porta nec. In congue, purus quis congue varius, tellus ipsum tempor est, in cursus tortor mauris sit amet odio. Pellentesque id tellus lacinia, molestie magna id, tincidunt libero. Etiam aliquam lorem in ultricies scelerisque. Vestibulum nulla lectus, tempus eu gravida at, vehicula eget eros.

Proin tempor pulvinar fringilla. Morbi elementum sagittis enim sit amet ullamcorper. Nulla sodales diam non nisi tempus, non porta sapien fermentum. Nulla facilisi. Vestibulum semper molestie fringilla. Etiam sed augue vitae sapien auctor viverra. Aliquam sapien magna, ornare a consectetur in, maximus ac ante. Nunc nulla nulla, rhoncus ut consequat ut, pellentesque quis libero. Phasellus hendrerit ipsum ac sollicitudin aliquam. Morbi sed nibh nec nisi ultricies faucibus non vel diam. Suspendisse sollicitudin blandit diam, eget ultrices nisl egestas eget. Curabitur pellentesque vulputate vehicula.

Aenean id augue erat. Aenean non mauris dolor. Nunc pretium lacus eget nisi faucibus, eget aliquam mauris scelerisque. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Mauris eleifend lacinia massa, vitae mattis velit ultricies in. Nulla sed erat ac ante maximus eleifend et id turpis. Nam aliquam sollicitudin urna ut volutpat. Quisque placerat accumsan libero, at elementum lacus consectetur ut.

In ex nibh, mattis in ex in, sodales efficitur massa. Mauris risus nisl, molestie vel scelerisque vitae, tempus ut felis. Integer a malesuada dui, non semper leo. Nulla placerat purus et pharetra consectetur. Nulla vel efficitur lorem. Vivamus nec magna eu purus bibendum efficitur. Quisque euismod risus tellus. Donec elementum eros vitae venenatis venenatis. Vestibulum ullamcorper, odio at hendrerit vestibulum, metus libero ornare eros, non facilisis tortor mauris sed purus. Proin ut massa facilisis, dignissim odio sit amet, vestibulum lectus.

Nulla pulvinar pharetra porta. Cras fringilla libero in lectus porttitor vehicula. Proin faucibus posuere est. Vivamus lacinia consectetur lacus, ut dignissim nisl vehicula eu. Mauris sagittis quam interdum orci efficitur, eget finibus risus sodales. Nam laoreet nulla at consequat dapibus. Aenean non nunc orci. Praesent ornare dapibus odio, eu pellentesque orci dignissim nec. Donec euismod massa turpis, at porta lorem pharetra at. Proin orci arcu, tristique vitae sollicitudin eget, congue at purus. Phasellus ut mi nulla. Donec eu maximus velit. Cras quis diam lobortis, tempus erat et, tincidunt nisl.

cderv commented 3 years ago

How are you rendering your document ? This is not the tufte style in your screenshot. Here is what I obtain with

> packageVersion("knitr")
[1] ‘1.31’
> packageVersion("tufte")
[1] ‘0.9’
> packageVersion("rmarkdown")
[1] ‘2.7’

and your code you posted above: https://rpubs.com/cderv/742766 See the fullwidth figure.

jtrakk commented 3 years ago
> library(rmarkdown)
> 
>  rmarkdown::render("my2.Rmd", encoding = "UTF-8", "html_document")

processing file: my2.Rmd
  |...............................................................                                                                                                                               |  33%
  ordinary text without R code

  |...............................................................................................................................                                                               |  67%
label: unnamed-chunk-1 (with options) 
List of 3
 $ fig.width    : num 30
 $ fig.height   : num 30
 $ fig.fullwidth: logi TRUE

  |..............................................................................................................................................................................................| 100%
  ordinary text without R code

output file: my2.knit.md

/nix/store/238q8ymczy3hsp59kymjpfsvvn36xih2-projectenv/bin/pandoc +RTS -K512m -RTS my2.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output my2.html --lua-filter /nix/store/my1qyysmf3wzd8d36q2lrc433wyfhdmv-R-4.0.3-wrapper/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /nix/store/my1qyysmf3wzd8d36q2lrc433wyfhdmv-R-4.0.3-wrapper/library/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --standalone --section-divs --template /nix/store/my1qyysmf3wzd8d36q2lrc433wyfhdmv-R-4.0.3-wrapper/library/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --variable 'theme:bootstrap' --include-in-header /tmp/RtmpmbhIDC/rmarkdown-strbf54ce67062.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' 

Output created: my2.html
cderv commented 3 years ago

rmarkdown::render("my2.Rmd", encoding = "UTF-8", "html_document")

You are specifying the format html_document here. So you are not using the tufte::tufte_html: default defined in the YAML header. rmarkdown::html_document format does not support fullwidth figure.

You need rmarkdown::render("my2.Rmd") which will run the first format in the YAML header. or rmarkdown::render("my2.Rmd", "tufte::tufte_html") if you want to precise the format in the call.

jtrakk commented 3 years ago

I see, that does work. Thank you.

github-actions[bot] commented 3 years ago

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.