[Tex/LaTex] ! LaTeX Error: Option clash for package geometry (but I haven’t loaded package twice)

package-options

I am currently trying to create a landscape document using r markdown. Since I also want the header to be in landscape, I have the following mystyles.sty document:

\usepackage[landscape]{geometry}
\usepackage{float}
\usepackage{subfigure}
\usepackage[table]{xcolor}
\usepackage{,pdflscape}

which is called in the header of my main document:

---
title: "Transition Matrix Report for 2015-01-20"
author: "Paul Lintilhac"
date: "Monday, February 2, 2015"
output:
  pdf_document:
    includes:
      in_header: mystyles.sty
---

however, when I try to knit the pdf, I get the error:

 ! LaTeX Error: Option clash for package geometry.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.62 \usepackage

pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc"     TransitionMatrix.utf8.md --to latex --from     markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output TransitionMatrix.pdf --template "C:\PROGRA~1\R\R-31~1.2\library\RMARKD~1\rmd\latex\default.tex" --highlight-style tango --latex-engine pdflatex --include-in-header mystyles.sty --variable "geometry:margin=1in"' had status 43 
Execution halted

I have checked many forums online, and they all seem to say that this error occurrs because I have tried to load a package with options twice. But clearly this is not the case. I have checked line 62 in the tex document produced by r markdown, and it is the line after calling usepackage[landscape]{geometry}. Getting rid of the other packages in mystyles.sty has no effect, however, when I go to the top of the tex document, I can see several other packages that are getting loaded automatically, as you can see at the top of the tex document copied below:

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript

\IfFileExists{microtype.sty}{\usepackage{microtype}}{}
\usepackage[margin=1in]{geometry}


\usepackage[landscape,width=15in,height=11.5in,top=.5in,bottow=.5in]{geometry}
\usepackage{float}
\usepackage{subfigure}
\usepackage[table]{xcolor}
\usepackage{,pdflscape}

I get the same error if I remove any of these except for \usepackage{ifxetex,ifluatex}
, which gives a different error.

What is going wrong here and how can I fix? Would really appreciate your help as I have been trying to get this stupid formatting correct for hours.

Best,

-Paul

Best Answer

\usepackage[margin=1in]{geometry}

and

\usepackage[landscape,width=15in,height=11.5in,top=.5in,bottow=.5in]{geometry}

look like loading twice to me.