I am making a pdf document in which I want two logos in the top right of the page. I found great examples of using the latex 'fancy' package. When I replicate the example I receive this error ! LaTeX Error: File 'fancyhdr.sty' not found. I am new to latex and have only used in Rstudio when knitting documents. How do I add this file or how do I install the latex package 'fancy'. I am using a 2017 macbook pro and making this document in R Studio.
---
title: "Test"
date: "Updated: `r format(Sys.time(), '%Y-%m-%d')`"
output: pdf_document
urlcolor: blue
indent: true
header-includes:
- \usepackage{indentfirst}
- \usepackage{graphicx}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[R]{\includegraphics[width=2cm]{ribbitr.png}}
- \fancyhead[L]{\includegraphics[width=2cm]{nsf_logo.png}}
- \renewcommand{\headrulewidth}{0.2pt}
- \renewcommand{\footrulewidth}{0.2pt}
---
Related
Given the code below, which currently outputs the page number on top of the page, I would like it to output the PDF page count as in Page 1 of 3. I have done a lot of searching but haven't found any way to include the total page number.
Question Is this possible to do w/ in R Markdown ? If not, are there any workarounds ?
I have googled this and haven't found anything obvious such as YAML or TeX solutions, however, I may be missing something or not searching for the correct things.
RMarkdown Code
---
title: "R Markdown Example With Numbered Sections"
output:
bookdown::pdf_document2:
toc: true
toc_depth: 6
number_sections: true
includes:
in_header: header.tex
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[RO,RE]{\thepage}
- \fancyhead[LO,LE]{Header Message}
- \fancyfoot[LE,LO]{Footer Messge on the Left}
- \fancyfoot[LE,RO]{Footer Messge on the Right}
---
\thispagestyle{fancy}
# Example R Rarkdown : Numbered Sections
## R Markdown
### Description
Some description text
\newpage
#### Details
Details go here.
\newpage
## Plots
Plots go here
\newpage
Last page
Current header
Desired Header
Make sure you have the lastpage package installed.
Then modify your header includes to look like this:
header-includes:
- \usepackage{fancyhdr}
- \usepackage{lastpage}
- \pagestyle{fancy}
- \fancyhead[RO,RE]{\thepage\ of \pageref{LastPage}}
- \fancyhead[LO,LE]{Header Message}
- \fancyfoot[LE,LO]{Footer Messge on the Left}
- \fancyfoot[LE,RO]{Footer Messge on the Right}
How to add background colors to specific section of the text while creating PDF reports using rmarkdown. Something like below
i tried something like this but it is working in latex but not in rmarkdown
\titleformat{\section}{\sffamily\Large\bfseries\rlap{\color{DarkGreen!90}\rule[-0.5ex]{\linewidth}{3ex}\vspace{-3ex}}\sffamily\Large\color{white}}{\thesection}{1em}{}
this is how it looks in latex
this is in rmarkdown
---
title: "Untitled"
output: pdf_document
header-includes:
- \usepackage{amsfonts,amssymb,amsmath}
- \usepackage[table, svgnames]{xcolor}
- \usepackage{titlesec}
- \usepackage{sectsty}
- \usepackage{xcolor, soul}
- \sectionfont{\color{red}}
- \subsectionfont{\color{green}}
- \subsubsectionfont{\color{blue}}
- \titleformat{\section}{\sffamily\Large\bfseries\rlap{\color{DarkGreen!90}\rule[-0.5ex]{\linewidth}{3ex}\vspace{-3ex}}\sffamily\Large\color{white}}{\thesection}{1em}{}
---
\section{Highlights}
# Section
Two problems:
rmarkdown already loads xcolor without paying attention to the options you need. As a workaround you could trick markdown by passing the necessary options to all packages
sectsty will destroy all changes you do via titlesec. Don't load them both
---
title: "Untitled"
output:
pdf_document:
keep_tex: true
classoption: svgnames
header-includes:
- \usepackage{amsfonts,amssymb,amsmath}
- \usepackage{titlesec}
- \usepackage{soul}
- \titleformat{\section}{\sffamily\Large\bfseries\rlap{\color{DarkGreen!90}\rule[-1.5ex]{\linewidth}{3ex}\vspace{-3.5ex}}\sffamily\Large\color{white}}{\thesection}{1em}{}
---
\section{Highlights}
# Section
I'm creating a PDF document using knitr and Rmarkdown but the logo-and-title are far from the top of the document.
How to reduce the top margin on the first page ? Many thanks in advance.
This is my code:
---
title: "Title come here (there is a logo before the title)"
output:
pdf_document:
header-includes:
- \usepackage{titling}
- \pretitle{\begin{center}
- \includegraphics[width=1.5in,height=1.5in]{logo.png}\LARGE\\}
---
I found a solution that works (not sure if it's a "clean" solution, but it does the job): I added a negative value in - \setlength{\droptitle}{-1.1in}
---
title: "\\vspace{0.5in} Title here"
output:
pdf_document:
header-includes:
- \usepackage{titling}
- \setlength{\droptitle}{-1.1in}
- \pretitle{\begin{center}
- \includegraphics[height=1.5in]{logo.png}\LARGE\\}
---
I am trying to learn Rmarkdown, but there is something that's quite elusive. I am trying to put my name at the top of every page of the PDF I print, however I also get the various headers from the text in the markdown file in the header, and it often overlaps and makes everything unreadable. I learned the basics from another thread on here, but still struggling. I only want my name in the header. I tried to modify it like what you see below, but then I don't get anything at all. This is my YAML:
---
title: "Something"
author: "something"
date: "42 42 42"
output: pdf_document
includes:
in_header: {My name}
fontsize: 12pt
header-includes:
\usepackage{setspace}
\onehalfspacing
---
Anyone who could write it so that I get only my name at the top of the page? Also, the onehalfspacing is the same as setting spacing to 1.5 in word right?
I think there is a conceptual problem: The things you put in includes: in_header: in the yaml are the files included in the preamble of your tex document, similar to what you have in header-includes:. This is not in any way related to the headline of your document.
If you like to change this, have a look at the fancyhdr latex package
Please also note that the syntax for multiline header-includes: is wrong in your example. You need to prefix each line with -
---
title: "Something"
author: "something"
date: "42 42 42"
output: pdf_document
fontsize: 12pt
header-includes:
- \usepackage{setspace}
- \onehalfspacing
- \usepackage{fancyhdr}
- \fancyhead[c]{your name}
- \pagestyle{fancy}
- \setlength{\headheight}{15pt}
---
test
\newpage
test
I have a text that I want to convert from latex to Markdown for various reasons. But I'm not able to make it work. If I load all the packages and only type "yo" as text, it's returning me an error.
Error in yaml::yaml.load(enc2utf8(string), ...) :
Scanner error: while scanning a directive at line 5, column 1could not find expected directive name at line 5, column 2
Calls: <Anonymous> ... yaml_load_utf8 -> mark_utf8 -> <Anonymous> -> .Call
Execution halted
Many people had this error before but I haven't saw somebody encountering this error so far and a solution for packages like this.
Can we write comments "%" in the preamble?
How can I add my latex packages in RMarkdown?
Will it work if I export it in word?
Here is my code:
---
title: "rest"
author: "Me"
date: '2016-10-26'
header-includes:
% Titles
- \usepackage{titlesec}
% figure
- \usepackage{color}
- \usepackage{graphicx} % Enhanced support for graphics
- \usepackage{subfig} % subfigure environment
- \usepackage{float} % Improved interface for floating objects
- \usepackage{rotating} % Rotation tools, including rotated full-page floats
% \usepackage[labelfont=bf]{caption} % Customising captions in floating environments
% tables
- \usepackage[table]{xcolor} % Driver-independent color extensions
- \usepackage{array} % Extending the array and tabular environments
- \usepackage{longtable} % Allow tables to flow over page boundaries
- \usepackage{multirow} % Create tabular cells spanning multiple rows
% math
- \usepackage{amssymb} % some weird math symbols
- \usepackage{amsthm}
- \usepackage{amsmath} % AMS mathematical facilities for LATEX
% documents aspect
- \usepackage{lineno} % Line numbers on paragraphs
- \usepackage[top=2.2cm, left=2.2cm,right=2.2cm,bottom=4.2cm]{geometry} % Flexible and complete interface to document d=imensions
% see geometry.pdf on how to lay out the page. There's lots.
- \usepackage[utf8]{inputenc} % Accept different input encodings
- \usepackage[T1]{fontenc}
- \usepackage{lscape} % Place selected parts of a document in landscape
- \usepackage{babel}
% reference in text
- \usepackage[unicode=true, pdfusetitle, bookmarks=true, bookmarksnumbered=false, bookmarksopen=false, breaklinks=true, pdfborder={0 0 0}, backref=page,colorlinks=true]
{hyperref}
- \newcommand*{\fullref}[1]{\hyperref[{#1}]{\autoref*{#1} \nameref*{#1}}}
% bibliography
%\usepackage[style=authoryear, backend=bibtex,bibencoding=ascii]{biblatex} % Bibliographies in LATEX using BibTEX for sorting only
- \usepackage{natbib} % Flexible bibliography support
% \usepackage{translation-natbib-fr} %French translation of the documentation of natbib
%\renewbibmacro{in:}{}
%\bibliography{yo.bib}
% \ref{} makes reference to a \label{} set in a table or figure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
- \theoremstyle{plain}
title: "data"
author: "Me"
date: '2016-10-26'
output:
pdf_document: default
word_document: default
documentclass: article % - \documentclass[english]{scrartcl
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
YO
Your header contains invalid YAML, inline comments need #:
---
title: "rest"
author: "Me"
date: '2016-10-26'
header-includes:
# Titles
- \usepackage{titlesec}
# figure
- \usepackage{color}
- \usepackage{graphicx}
...
You'll also need to de-duplicate your YAML map keys. Sure, you can render RMarkdown to Word with the obvious caveat that LaTeX-specific formatting won't automagically carry over.