-
DescriptionHello, Is there a way to define the max width for figures non generated by code as a global option? For the generated content there is a Let's say I want the images to be 75% of the linewidth; I can always do this:
but this needs to be applied to each image in the document, and also if later I want to change the value (e.g. 80%), I would need to change for each image. What I would like to do is set a global option in the yaml section, easily modifiable, to act as the default width for all the figures in the document, unless otherwise specified at the local level like in the above example. This should work both for html and pdf output (probably others too). I am doing a images report, which contains a lot of figures, so being able to set a global width for the whole documents is quite handy, also because I can then regulate the width to have at least 2 figures per page in the pdf output. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Could you share a small self-contained "working" (reproducible) example to work with, i.e., a complete Quarto document or a Git repository? Thanks. You can share a Quarto document using the following syntax, i.e., using more backticks than you have in your document (usually four ````qmd
---
title: "Reproducible Quarto Document"
format: html
---
This is a reproducible Quarto document using `format: html`.
It is written in Markdown and contains embedded R code.
When you run the code, it will produce a plot.
```{r}
plot(cars)
```
The end.
```` |
Beta Was this translation helpful? Give feedback.
-
You need to apply attributes on figures individually using Markdown syntax as explained in https://quarto.org/docs/authoring/figures.html#figure-sizing If you want to apply an attributes on all items in a document, you may leverage Lua filters for that as it would allow you to tweak the document programatically (https://quarto.org/docs/extensions/filters.html) You would target for example all Otherwise, know that you could do that globally with other tech. For example if you target HTML output, you could use CSS to change size of all Anyhow, you can't do that using a Quarto option for now. |
Beta Was this translation helpful? Give feedback.
-
FYI, a quick and dirty JavaScript script: ---
include-in-header:
- text: |
<script type="text/javascript">
window.addEventListener('load', function() {
const figures = document.querySelectorAll('figure');
const images = document.querySelectorAll('img');
figures.forEach(figure => {
figure.style.width = '75%';
});
images.forEach(image => {
image.style.width = '75%';
});
});
</script>
---
 |
Beta Was this translation helpful? Give feedback.
-
Thanks, that useful to know. To achieve this for the pdf output I've used the format:
pdf:
include-in-header:
text: \setkeys{Gin}{width=0.75\linewidth} I would say though that the |
Beta Was this translation helpful? Give feedback.
fig-width
only works for figures generated by computations as we document at https://quarto.org/docs/reference/formats/html.html#figuresYou need to apply attributes on figures individually using Markdown syntax as explained in https://quarto.org/docs/authoring/figures.html#figure-sizing
If you want to apply an attributes on all items in a document, you may leverage Lua filters for that as it would allow you to tweak the document programatically (https://quarto.org/docs/extensions/filters.html)
You would target for example all
Image
element, and add awidth