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
Add figure notes option #2022
Comments
|
That sounds like a reasonable feature request. I feel it shouldn't be too hard to implement for LaTeX output, but could be challenging when considering other output formats. |
|
I had asked this question almost two years ago in <figure>
<figcaption>Wikipedia logo</figcaption>
<img src="https://upload.wikimedia.org/wikipedia/commons/0/07/Wikipedia_logo_%28svg%29.svg">
<p>Lorem ipsum dolor sit amet.</p>
</figure>Hope this might help (indeed would be a very useful feature) |
|
If it can help, I propose below snippets written by @RLesur, @JulietteS and I toimplement in HTML this functionality. I think it had the inconvenient of breaking the automatic numbering of figures (@RLesur and @JulietteS : am I correct ?) At caption_above <- function(x, options, ...){
notes <- ""
if (!is.null(options$fig.subnotes)){
notes <- sprintf("<figsubnotes>%s</figsubnotes>", options$fig.subnotes)
}
fignumber <- ""
if (!is.null(options$fig.number)){
fignumber <- sprintf("<fignumber>%s</fignumber>", options$fig.number)
}
paste(
'<figure>',
fignumber,
'<figcaption>',
options$fig.cap,
'</figcaption><img src="',
knitr::opts_knit$get('base.url'),
paste(x, collapse = '.'),
'">',
notes,
'</figure>',
sep = '')
}We were using a custom output format (overcharging of$knitr$knit_hooks <- list(plot = caption_above)Finally, I tried to recollect our different CSS elements to control the position of the note (colors were defined in our CSS as variables, you can of course get rid of these elements): figure > figsubnotes {
font-family: var(--title-font);
font-size:7pt;
}
figure figcaption {
font-family: var(--title-font);
font-size:9pt;
font-weight:bold;
}
figure figcaption {
background-color: var(--theme-color-light);
color: #333333;
padding: 2pt 10pt;
z-index: 1;
text-indent: 5pt;
}
/* hack to avoid break before figure subnotes */
figure > figsubnotes::before {
content: "";
display: block;
height: 70px;
margin-top: -70px;
}
figure > figsubnotes {
break-inside: avoid;
}
fignumber {
background-color: var(--theme-color-dark);
z-index: 2;
padding: 1pt 5px;
color: white;
font-family: var(--body-font);
font-weight: bold;
position: relative;
top: 8pt;
}And finally we were using this as a chunk option in our Rmd: There's maybe easier paths to implement this feature for HTML output. I hope, at least, these snippets might help (once again this was a collective effort and most of the great ideas came from @RLesur and @JulietteS) |
|
Thanks a lot for the suggestion! For me personally, the issue is more pressing in LaTeX/PDF output than in HTML because figures don't float in HTML. So even if I did not know how to make figure notes part of the figure itself, I could at least put them somewhere close to the figure and add some styling with CSS. LaTeX, on the other hand, removes figures from the surrounding stream of text and puts them in an appropriate spot. So figure notes would have to be part of the figure environment to prevent them from being detached from the figure itself. Unfortunately, the figure environment is created by The issue is of course even more complex because LaTeX itself (leaving R Markdown aside) by default does not even offer semantic markup for figure notes. I'd suggest adding such a field by defining a custom command somewhere in the preamble, e.g. with the \documentclass{article}
\usepackage{floatrow}
\newcommand{\figsourcenote}[1]{\floatfoot{#1}}
\begin{document}
\begin{figure}
\centering
\includegraphics[...]{...}
\caption{...}
\figsourcenote{\emph{Note:} ...}
\end{figure}
\end{document}That way, the user could re-define the command |
|
I want to endorse this idea as well. I saw this discussion in Stack Overflow on using custom hooks in a .Rnw file. Is there a way to implement this strategy (using custom hooks) in an .Rmd file? |
|
I'd like to second this. Hope to see this feature implemented soon! |
|
as i'm slowly moving my reports to quarto, would be great if the solution applied to .Rmd could also travel to the new .qmd format. and by the way, thanks for the great work! |
In my field it seems customary to separate the title/short description of a figure from its notes (containing lengthy details), similar to
Is there any way to accomplish this with Rmarkdown/knitr or would it make sense to add a chunk option specifically for this purpose? Stack Overflow offers one solution for latex documents that works and surprisingly does not even result in ugly latex code.
However, the markup in the Rmarkdown file is verbose and other output formats won't accept the code. Many packages for producing tables have an option to provide both a title and notes, for example
But I am not aware of a package that allows producing figures with captions that are not baked into the actual image file. So in my opinion, a chunk option for this purpose would be a welcome addition although I do not know how and whether this could be implemented and whether you like the idea at all. For latex specifically, I was thinking that perhaps the existing chunk option
fig.scapcould be used because I assume in most cases the short title of a figure would also be used in the list of figures (抛砖引玉而已). But I do not know of a way to have Latex print this short caption outside of the list of figures.By filing an issue to this repo, I promise that
xfun::session_info('knitr'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('yihui/knitr').I understand that my issue may be closed if I don't fulfill my promises.
The text was updated successfully, but these errors were encountered: