Insert a logo in upper right corner of R markdown pdf document

后端 未结 5 1457
挽巷
挽巷 2020-12-01 03:21

I am getting started with R markdown and I would like to create a new report having our company image logo.png in the upper right corner of each page.

I

相关标签:
5条回答
  • 2020-12-01 03:29

    You can use the includes option in the yaml to specify a custom addition to your latex header. The yaml part would look like

    ---
    output: 
        pdf_document:
          keep_tex: true
          includes:
              in_header: header.tex
    ---
    

    and you need to save a separate file called header.tex with the following defining your company logo like so:

    \usepackage{fancyhdr}
    \pagestyle{fancy}
    \rhead{\includegraphics[width = .05\textwidth]{logo.png}}
    

    Here I used the fancyhdr latex package to add the logo, but there are other potential solutions. See here for more options.

    0 讨论(0)
  • 2020-12-01 03:31

    Ok, I have found the solution:

    ---
    title:
    header-includes: 
       \usepackage{graphicx}
       \usepackage{fancyhdr}
       \pagestyle{fancy}
       \setlength\headheight{28pt}
       \fancyhead[L]{\includegraphics[width=5cm]{GPIM_Logo_300x85.png}}
       \fancyfoot[LE,RO]{GPIM}
    output: pdf_document
    ---
    
    0 讨论(0)
  • 2020-12-01 03:31

    I've tried many solutions presented here and in other forums, none of which worked. I've finally came to a solution that worked for me.

    ---
    title: 'Fancy Title Here'
    author: "Diego"
    date: "today"
    output:
      pdf_document:
        toc: yes
    header-includes:
        - \usepackage{fancyhdr}
    ---
    \addtolength{\headheight}{1.0cm} % make more space for the header
    \pagestyle{fancyplain} % use fancy for all pages except chapter start
    \rhead{\includegraphics[height=1.2cm]{C:/Path/to/logo/logo}} % right logo
    \renewcommand{\headrulewidth}{0pt} % remove rule below header
    

    I hope that helps someone the same way it helped me.

    0 讨论(0)
  • 2020-12-01 03:33

    For those using flexdashboardsee this addition to entry preamble text for logos and favicon, although its upper left not right:

    http://rmarkdown.rstudio.com/flexdashboard/using.html#logo__favicon

    so your start of the .Rmd file looks like this:

    ---
    title: "myappR"
    output:
      flexdashboard::flex_dashboard:
        logo: mylogo.png
        favicon: mylogo.png
        theme: bootstrap
    runtime: shiny
    ---
    

    I left my logo in the root directory with a simple name. And:

    • Kept logo height 48 pixels as this plays nicely with the theme,
    • Be careful of spaces and indents and,
    • Do not forget the ending : after flexdashboard.
    0 讨论(0)
  • 2020-12-01 03:55

    I have found a solution to make a logo only on the first page:

    \addtolength{\headheight}{1.0cm} % make more space for the header
    \fancypagestyle{plain}{} % this is to remove the default plain style for the first page
    \thispagestyle{fancy} % use fancy for all pages except chapter start
    \fancyhead[L]{\includegraphics[width = 100pt]{ManchesterLogo.png}}
    \renewcommand{\headrulewidth}{0pt} % remove rule below header
    
    0 讨论(0)
提交回复
热议问题