LaTeX Error: File `fancyhdr.sty' not found.

Install R (R i386 4.0.5, R x64 4.0.5), RStudio (1.4.1106), MiKTeX 2.9 and TinyTeX in a virtual machine on Window 10 x64 based environment.

Run .rmd program and - \usepackage{fancyhdr} statement on the header-includes section; the report generating pdf output failed. Message on R Markdown tab:

Can't locate Win32/ in @INC (you may need to install the Win32::API module) (@INC contains: C:/Users/nli/AppData/Roaming/TinyTeX/texmf-dist/scripts/texlive C:/Users/nli/AppData/Roaming/TinyTeX/tlpkg C:\Users\nli\AppData\Roaming\TinyTeX\tlpkg\tlperl\lib C:/Users/nli/AppData/Roaming/TinyTeX/tlpkg/tlperl/site/lib C:/Users/nli/AppData/Roaming/TinyTeX/tlpkg/tlperl/lib) at C:/Users/nli/AppData/Roaming/TinyTeX/tlpkg/TeXLive/ line 129.

BEGIN failed--compilation aborted at C:/Users/nli/AppData/Roaming/TinyTeX/tlpkg/TeXLive/ line 143.

Compilation failed in require at C:/Users/nli/AppData/Roaming/TinyTeX/tlpkg/TeXLive/ line 103.

BEGIN failed--compilation aborted at C:/Users/nli/AppData/Roaming/TinyTeX/tlpkg/TeXLive/ line 103.

Compilation failed in require at C:\Users\nli\AppData\Roaming\TinyTeX\texmf-dist\scripts\texlive\ line 91.

BEGIN failed--compilation aborted at C:\Users\nli\AppData\Roaming\TinyTeX\texmf-dist\scripts\texlive\ line 91.

! LaTeX Error: File `fancyhdr.sty' not found.

Does anyone know how to solve this problem? Thanks in advance.

I don't use Windows but the Latex error suggests that the fancyhdr package needs to be installed. Tinytex is as it says tiny and it is unlikely to have fancyhdr.

No idea how to install a latex package in Windows but I think it is covered in yihui's Rmarkdown book

Thank you so much for the quick reply. I've installed MiKTeX 2.9 and it should work as the error message indicated. Anyway, it doesn't work for my.

A MiKTeX installation should do it but can you check for sure that fancyhdr is there?

IIRC, it is not in the standard TeXLive installation and while I have it now, on my original installation 6--7 years ago I had to install it separately. Now, when setting up a new computer, I say the heck with diskspace and download everything.

Do you still have Tinytex installed? If so, can you be sure that you are compiling with MiXText? I am a Linux user so I have no idea how Windows will handle things.

The other thing, you could post a cut-down copy of your .rmd file and someone can have a shot at running it. I can give it a try but even better would be another Windows user.

Good luck.

I've installed basic-miktex-21.2-x64 application; it seems like RStudio can't find MiKTex for some reason. I don't know how to install and check fancyhdr package installed .

Have you deleted Tinytex?

Can you give use a cut-down version of your .rmd file to test. Ju-t the YAMAL annd a few lines of body text should be sufficient.

I don't know either. We need a Windows person to help.

You can add the missing LaTeX package to tinytex via tinytex::tlmgr_install("fancyhdr")

1 Like

After ran above, here is the message
Can't locate Win32/ in @INC (you may need to install the Win32::API module)

  • Win32/ ??? what is it? from where? Thank you
title: "try"
- \usepackage{fancyhdr}
- \addtolength{\headheight}{1.0cm} 
- \pagestyle{fancyplain}
- \lhead{\includegraphics[height=1.2cm]{L:/Statunit/Dashboard Reports/Common Functions/TJC_logo_color.png}}
- \renewcommand{\headrulewidth}{0pt} 
- \usepackage{comment}
- \usepackage{float}

geometry: margin=2cm
  latex_engine: xelatex
  html_document: default
  word_document: default
urlcolor: blue
classoption: landscape


```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <>.

Sorry - I work with mac and linux. My best guess is that something is wrong with the PERL installation: Can't locate Win32/API/

Thank for the .rmd file. I was just checking that it was running okay and everything seems fine though I had to remove the logo code.

A quick google brings up this Win32::API - Perl Win32 API Import Facility -
but like @jrmuirhead I am not a Windows person.

It might be worth posting on a Windows forum for help with Win32::API. Someone here will know but a lot of us are Mac or Linux and you should get a faster answer on a Windows forum

Thank you so much. Same .rmd file runs as expected and generate pdf report in my laptop. Now we are migrating R/RStudio to virtual machine (remote desk) - on server maybe?? That may cause the problem. Not sure laptop and server using same version of R/RStudio.

Hi @tjcnnl1

Is this with a recent TInyTeX installation ? You could try updating to last release.


or reinstalling


Maybe it will help.

BTW I am on Windows and the document compiles fine for me.

Awesome! After reinstall tinytex (version from 0.3 to .31) it works. Thank you.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.