knitr, side-by-side images with padding/margin between

Hi, I have 2 images and I want to render them side by side in both LaTeX (pdf) and gitbook (html) format.

This works fine on pdf, but not on html:

```{r side-by-side, fig.show='hold', out.width='45%',}

include_graphics("path_to_image1")
include_graphics("path_to_image2")

In the html output, there is no white space, margin, padding between images. I want some gap between images. I feel like there must be an option but I couldn't find it. Is there a way to set this without editing CSS?

1 Like

Centering and width both work for me doing this:

``` {r, echo=FALSE, fig.align='center', out.width='50%'}
knitr::include_graphics("images/sepialogo.png")

Do the commands you have included work but just not nicely styled?

If so I'm guessing you'll just need to edit the CSS.

2 Likes

It works but not styled the way I want.

HTML Output:

PDF Output:

I want the images side-by-side with a little space between in html format. I can edit the CSS, no problem but I was just thinking there must be an option I can set in the code chunk.

You can try including a blank, spacer image