简体   繁体   中英

Inserting logo into beamer presentation using R Markdown

I am trying to insert logo into beamer presenation using Rmarkdown, and it looks like size controls in \logo{\includegraphics[height=1cm,width=3cm]{logo.png}} do not work, no matter what values I put there, image is always of the same size. Any suggestions besides modifying image manually?

---
title: "Presentation"
author: "Author"
output:
  beamer_presentation:
    includes:
      in_header: mystyle.tex

---

## R Markdown

This is an R Markdown presentation. Markdown is a simple formatting
syntax for authoring HTML, PDF, and MS Word documents. For more
details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that
includes both content as well as the output of any embedded R code
chunks within the document.

## Slide with Bullets

- Bullet 1
- Bullet 2
- Bullet 3

## Slide with R Code and Output

```{r}
summary(cars)
```

## Slide with Plot

```{r, echo=FALSE}
plot(cars)
```

This is mystyle.tex

\logo{\includegraphics[height=1cm,width=3cm]{logo.png}}
\usetheme{Madrid}
\usefonttheme{serif}
\institute{Institute}
\setbeamertemplate{navigation symbols}{}

UPDATE: Quick work around - simply modifying image will not work - image is ugly and pixelated. Simply converting to pdf also didn't work well, so I used following R code to create pdf and use it in \logo{\includegraphics{logo.pdf}}

library(png)
library(grid)
img <- readPNG('logo.png')
img <- rasterGrob(img, interpolate=TRUE)
pdf(file = 'logo.pdf', width = 1, height = 0.25)
grid.newpage()
grid.raster(img)
dev.off()

I found solution; in beamer manual there is another way of using logo function and it works fine.

\pgfdeclareimage[height=0.2787cm, width=2.5cm]{logo}{logo.png}
\logo{\pgfuseimage{logo}}

I found this beamer tutorial quite useful. Just add the following to the file mystyle.tex passed to the YAML option in_header (as shown in the question):

\usepackage{tikz}
\titlegraphic { 
\begin{tikzpicture}[overlay,remember picture]
\node[left=0.2cm] at (current page.30){
    \includegraphics[width=3cm]{Beamer-Logo}
};
\end{tikzpicture}
}

and then you can play around with the node parameters to adjust the placement of your logo ( Beamer-Logo ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM