Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to PassOptionsToPackage from inside a quarto document?

Consider the following quarto document:

---
title: "Some title"
author: X
date: "2022"
format: 
  pdf:
   number-sections: true
   fontsize: 12 pt
   papersize: A4
   fig-pos: 'H'
   geometry: "left=2.54cm,right=2.54cm,top=2.54cm,bottom=2.54cm"
   include-in-header:
     text: |
       \usepackage[font=small]{caption}
       \usepackage{float}
       \usepackage[table]{xcolor}

engine: jupyter
jupyter: r-reticulate
---

\begin{center}
\begin{tabular}{|c|c|}
\hline 
1 & 2\tabularnewline
\hline 
\cellcolor{blue} 3 & \cellcolor{red} 4\tabularnewline
\hline 
\end{tabular}
\end{center}

I get the following error, when rendering it:

LaTeX Error: Option clash for package xcolor.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.83 \KOMAoption
                {captions}{tableheading} 

A solution that works is to add table to the following line of the tex file generated by quarto:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor}

That is:

\PassOptionsToPackage{dvipsnames,svgnames,x11names, table}{xcolor}

My question is: How can I do that from inside the quarto document instead of hacking the tex file?

>Solution :

As explained in this answer on Tex StackExchange, one possible solution could be passing table as a classoption and you do not need to declare using xcolor explicitly since it is used by-default.

---
title: "Some title"
author: X
date: "2022"
format: 
  pdf:
   number-sections: true
   fontsize: 12 pt
   papersize: A4
   fig-pos: 'H'
   geometry: "left=2.54cm,right=2.54cm,top=2.54cm,bottom=2.54cm"
   classoption: table
   include-in-header:
     text: |
       \usepackage[font=small]{caption}
       \usepackage{float}
---

\begin{center}
\begin{tabular}{|c|c|}
\hline 
1 & 2\tabularnewline
\hline 
\cellcolor{blue} 3 & \cellcolor{red} 4\tabularnewline
\hline 
\end{tabular}
\end{center}

renderd pdf output


Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading