Skip to content
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 an option for adding subfloat separators #2116

Closed
3 tasks done
jakubkaczor opened this issue Mar 28, 2022 · 8 comments · Fixed by #2140
Closed
3 tasks done

Add an option for adding subfloat separators #2116

jakubkaczor opened this issue Mar 28, 2022 · 8 comments · Fixed by #2140
Labels
feature Feature requests help needed We need your help with the issue/PR

Comments

@jakubkaczor
Copy link

Currently, LaTeX code generated for sub floats places them one by one without separation. This results in adjacent images, as well as captions, in the output. It would be very handy to have an option to specify separator. One could write something like fig.subsep = "\\hfill", what would result with something like

\subfloat{\includegraphics[width=0.49\textwidth]{…} }
\hfill % here, the separator
\subfloat{\includegraphics[width=0.49\textwidth]{…} }

Here is an extreme illustration of the problem with the out.width set to 30 percent.
image
It would also be useful to specify separators not only in between the sub figures, but also before and after the first one and the last one respectively. This would allow more flexible layouts and centering sub figures in columns. From the interface perspactive, perhaps this could be achieved by passing a vector of separators. Eg. fig.subsep=c("\\hspace {1 cm}", "\\hfill", "\\hspace {1 cm}").


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included 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').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@yihui
Copy link
Owner

yihui commented Mar 29, 2022

I'm okay with adding this chunk option, but I may not have enough time to do it. Would you be willing to implement it by yourself and send a pull request? Thanks!

hook_plot_tex = function(x, options) {

@yihui yihui added feature Feature requests help needed We need your help with the issue/PR labels Mar 29, 2022
@jakubkaczor
Copy link
Author

jakubkaczor commented Mar 30, 2022

I'm time constrained also, but if I find some, I will definitely take a look at it. Not later than in the summer. 😅 Not promising, though. 😉 Thank you for pointing to the place in code.

@pedropark99
Copy link
Contributor

I have open a PR with the necessary changes to add such option (#2140);

@yihui
Copy link
Owner

yihui commented Jun 29, 2022

@jakubkaczor I just merged @pedropark99's PR, and you may try the dev version now (with the chunk option you proposed, i.e., fig.subsep=c("\\hspace {1 cm}", "\\hfill", "\\hspace {1 cm}")):

remotes::install_github('yihui/knitr')

@yihui
Copy link
Owner

yihui commented Jun 29, 2022

Oh wait a minute. It turns out that I have already had a chunk option fig.sep for separating subfigures and I have totally forgotten it: https://yihui.org/knitr/options/ Let me see what's going on...

@yihui yihui reopened this Jun 29, 2022
@yihui yihui closed this as completed in 2cfe22d Jun 29, 2022
@yihui
Copy link
Owner

yihui commented Jun 29, 2022

I've extended the existing fig.sep option (and removed fig.subsep), so that you can use fig.sep=c("\\hspace {1 cm}", "\\hfill", "\\hspace {1 cm}") when there are two plots in a chunk.

@jakubkaczor
Copy link
Author

Thanks! I tested it and it worked. 😉

yihui added a commit to yihui/yihui.org that referenced this issue Jul 6, 2022
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Feature requests help needed We need your help with the issue/PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants