![xcolor 和 tikz 之间的冲突](https://linux22.com/image/432349/xcolor%20%E5%92%8C%20tikz%20%E4%B9%8B%E9%97%B4%E7%9A%84%E5%86%B2%E7%AA%81.png)
我可以运行这个代码
\documentclass[11pt]{article}
\input{styles_optique}
\begin{docuemnt}
\begin{tikzpicture}
\def \y {2};%demi hauteur de la lentille
\def \Ra {3};%rayon de la première face
\def \Rb {5};%rayon de la face de sortie
\def \anglea {asin(\y/\Ra)};
\def \angleb {asin(\y/\Rb)};
\def \ep {\Rb+\Ra-sqrt(\Rb*\Rb-\y*\y)-sqrt(\Ra*\Ra-\y*\y)};
\coordinate (O) at (0,0);
\coordinate (B) at (0,\y);
\coordinate (A) at (0,-\y);
\coordinate (C1) at ({sqrt(\Ra*\Ra-\y*\y)},0);
\coordinate (C2) at ({-sqrt(\Rb*\Rb-\y*\y)},0);
\coordinate (S1) at ({sqrt(\Ra*\Ra-\y*\y)-\Ra},0);
\coordinate (S2) at ({\Rb-sqrt(\Rb*\Rb-\y*\y)},0);
\draw (C2)--(B) node[midway,fill=white]{$R_{2}$}--(A)--(C1)node[midway,fill=white]{$R_{1}$};
\draw[verre] (A) arc({180+\anglea}:{180-\anglea}:\Ra) arc({\angleb}:{-\angleb}:\Rb);
\draw[thin,->] (-5,0)--++(8,0)node[above]{\small axe optique};
\foreach \x/\xtex in {C1/$\mathrm{C_{1}}$,C2/$\mathrm{C_{2}}$,S1/$\mathrm{S_{1}}$,S2/$\mathrm{S_{2}}$}
\draw[shift={(\x)}] (0pt,2pt) -- (0pt,-2pt) node[below] {\xtex};
\draw[shift={(S1)},|<->|] (0,20pt)--++({\ep},0) node[pos=0.5,above]{e};
\draw (0,-\y)node[above=20pt]{\small $n$};
\end{tikzpicture}
\end{document}
但当我将它与这些包一起插入时却不行:
\documentclass[a4paper, 11pt]{article}
\usepackage{geometry}
\geometry{hmargin=2cm,vmargin=1.5cm}
\usepackage{graphicx}
\usepackage{pifont}
\usepackage{amssymb}
\usepackage{fontawesome}
\newcommand{\textding}[1]{\text{\ding{#1}}}
\usepackage[T1]{fontenc}
\usepackage[table,xcdraw]{xcolor}
\usepackage{textcomp}
\usepackage{enumitem}
\usepackage{amsmath}
\usepackage[polutonikogreek,french]{babel}
\usepackage{fancyhdr}
\usepackage{fancybox}
\usepackage{lastpage}
\usepackage[version=4]{mhchem}
\usepackage{pdfpages}
\usepackage[tikz]{bclogo}
\usepackage{listings}
\usepackage{pgfplots}
\usepackage{multicol}
\geometry{a4paper}
\usepackage{chemist}
\usepackage[most]{tcolorbox}
\usepackage{pst-all}
\usepackage{url}
\setlength{\textwidth}{18cm}
\usepackage{xcolor}
\definecolor{mycolor}{rgb}{0.122, 0.435, 0.698}
\newtcbox{\mybox}{on line,
colframe=mycolor,colback=mycolor!33!white,
boxrule=0.5pt,arc=4pt,boxsep=0pt,left=6pt,right=6pt,top=1pt,bottom=4pt}
\usepackage{sectsty}
\newtcolorbox{xp1}[2][]{
lower separated=false,
colback=white!80!gray,
colframe=white, fonttitle=\bfseries,
colbacktitle=white!50!gray,
coltitle=black,
enhanced,
attach boxed title to top left={xshift=0.5cm,yshift=-2mm},
title=#2,#1}
\newtcolorbox{def1}[2][]{
lower separated=false,
colback=white,
colframe=black,fonttitle=\bfseries,
colbacktitle=black,
coltitle=white,
enhanced,
attach boxed title to top left={yshift=-0.1in,xshift=0.15in},
boxed title style={boxrule=0pt,colframe=white,},
title=#2,#1}
\newtcolorbox{prop}[2][]{
lower separated=false,
colback=black!2,
colframe=white!0!black,fonttitle=\bfseries,
colbacktitle=white!50!,
coltitle=black,
enhanced,
attach boxed title to top left={xshift=0.5cm,
yshift=-2mm},
title=#2,#1}
\sectionfont{\color{red}}
\subsectionfont{\color{blue}}
\pagestyle{fancy}
\renewcommand\headrulewidth{1pt}
\fancyhead[L]{Les lentilles minces convergentes}
\fancyhead[R]{Signaux}
\fancyhead[C]{}
\renewcommand\footrulewidth{1pt}
\fancyfoot[R]{}
\fancyfoot[C]{\thepage}
\fancyfoot[L]{}
\usepackage{helvet}
\usepackage{array,multirow,makecell}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash }b{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash }b{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash }b{#1}}
\input{styles_optique}
\begin{document}
\documentclass[a4paper, 11pt]{article}
\usepackage{geometry}
\geometry{hmargin=2cm,vmargin=1.5cm}
\usepackage{graphicx}
\usepackage{pifont}
\usepackage{amssymb}
\usepackage{fontawesome}
\newcommand{\textding}[1]{\text{\ding{#1}}}
\usepackage[T1]{fontenc}
\usepackage[table,xcdraw]{xcolor}
\usepackage{textcomp}
\usepackage{enumitem}
\usepackage{amsmath}
\usepackage[polutonikogreek,french]{babel}
\usepackage{fancyhdr}
\usepackage{fancybox}
\usepackage{lastpage}
\usepackage[version=4]{mhchem}
\usepackage{pdfpages}
\usepackage[tikz]{bclogo}
\usepackage{listings}
\usepackage{pgfplots}
\usepackage{multicol}
\geometry{a4paper}
\usepackage{chemist}
\usepackage[most]{tcolorbox}
\usepackage{pst-all}
\usepackage{url}
\setlength{\textwidth}{18cm}
\usepackage{xcolor}
\definecolor{mycolor}{rgb}{0.122, 0.435, 0.698}
\newtcbox{\mybox}{on line,
colframe=mycolor,colback=mycolor!33!white,
boxrule=0.5pt,arc=4pt,boxsep=0pt,left=6pt,right=6pt,top=1pt,bottom=4pt}
\usepackage{sectsty}
\newtcolorbox{xp1}[2][]{
lower separated=false,
colback=white!80!gray,
colframe=white, fonttitle=\bfseries,
colbacktitle=white!50!gray,
coltitle=black,
enhanced,
attach boxed title to top left={xshift=0.5cm,yshift=-2mm},
title=#2,#1}
\newtcolorbox{def1}[2][]{
lower separated=false,
colback=white,
colframe=black,fonttitle=\bfseries,
colbacktitle=black,
coltitle=white,
enhanced,
attach boxed title to top left={yshift=-0.1in,xshift=0.15in},
boxed title style={boxrule=0pt,colframe=white,},
title=#2,#1}
\newtcolorbox{prop}[2][]{
lower separated=false,
colback=black!2,
colframe=white!0!black,fonttitle=\bfseries,
colbacktitle=white!50!,
coltitle=black,
enhanced,
attach boxed title to top left={xshift=0.5cm,
yshift=-2mm},
title=#2,#1}
\sectionfont{\color{red}}
\subsectionfont{\color{blue}}
\pagestyle{fancy}
\renewcommand\headrulewidth{1pt}
\fancyhead[L]{Les lentilles minces convergentes}
\fancyhead[R]{Signaux}
\fancyhead[C]{}
\renewcommand\footrulewidth{1pt}
\fancyfoot[R]{Lycée JP Timbaud}
\fancyfoot[C]{\thepage}
\fancyfoot[L]{2nd}
\usepackage{helvet}
\usepackage{array,multirow,makecell}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash }b{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash }b{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash }b{#1}}
\input{styles_optique}
\begin{document}
test
\end{document}
错误信息
! LaTeX Error: Option clash for package xcolor.
这是样式 optique.tex:
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc,arrows,fadings,decorations.pathreplacing,decorations.markings,patterns,shapes.geometric}
\usepackage{fp}
\pgfplotsset{compat=1.9}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
%------ styles tikz ---------------
\tikzset{>=stealth,inner sep=0pt, outer sep=2pt,}
\tikzset{tiret/.style={gray,dashed}}
\tikzset{doublefleche/.style={|<->|,>=stealth,thin}}
\tikzset{bloc/.style={rounded corners=4pt,color=white,ball color=purple,smooth}}
\tikzset{force/.style={->,ultra thick,rounded corners=4pt,color=blue,smooth,line cap=round}}
\tikzset{vecteur/.style={->,thick,color=black,smooth}}
\tikzset{verre/.style={draw=SkyBlue,fill=SkyBlue!30}}
\tikzset{axis/.style={thin,gray}}
\tikzset{figure/.style={thick,color=#1,fill=purple, opacity=0.5}}
\tikzset{ressort/.style={very thick,black,smooth}}
\tikzset{eau/.style={draw=black,fill=blue,opacity=0.5}}
%-----------------------------------
% Commande \oeil
\newcommand{\oeil}[1][] % rouge par dÈfaut
{
\draw[#1,thick,rounded corners] (-15:1)--(0,0)--(15:1);
\draw[#1] (-15:0.8) arc (-15:15:0.8);
\draw[#1,fill=black] (0:0.75) ellipse(0.05 and 0.1);
}
% \photon{options}{nombre}{énergie} symbole du photon centré en (0,0)
\newcommand{\photon}[3]%
{
\draw[#1] (-0.5,0) node {\tiny $\bullet$};
\draw[#1,decoration={coil,aspect=0,segment length=2mm,amplitude=2mm},decorate] (-0.5,0)--++(1,0)node[midway,above=3mm]{#2};
\draw[#1,->](0.5,0)--++(0.2,0)node[right]{#3};
}
\newcommand{\photongauche}[3]%
{
\draw[#1] (0.5,0) node {\tiny $\bullet$};
\draw[#1,decoration={coil,aspect=0,segment length=2mm,amplitude=2mm},decorate] (0.5,0)--++(-1,0)node[midway,above=3mm]{#2};
\draw[#1,->](-0.5,0)--++(-0.2,0)node[left]{#3};
}
% Commande \collimateur : collimateur1cmx3cm centré sur la fente d'entrée
\newcommand{\collimateur}[1]
{
\draw[#1,thick,|-|](0,0.1)--++(0,0.4)--++(3,0)--++(0,-1)--++(-3,0)--++(0,0.4);
\draw[#1,<->,>=latex](2.8,-0.5)--++(0,1);
}
% commande \lunette : lunette 4x1cm centrée surle réticule.
\newcommand{\lunette}[1]
{
\draw[#1,dashed](-1,0)--(4,0);
\draw[#1,dashed](0,-0.4)--++(0,0.8);
\draw[#1,gray, thick](-0.4,-0.45)--++(0.8,0);
\draw[#1,gray, thick](-0.4,0.45)--++(0.8,0);
\draw[#1,ultra thick](-1,-0.4)--++(0.8,0);
\draw[#1,ultra thick](-1,0.4)--++(0.8,0);
\draw[#1,ultra thick](0.2,-0.5)--++(2.8,0);
\draw[#1,ultra thick](0.2,0.5)--++(2.8,0);
\draw[#1,<->,>=latex](2.8,-0.5)--++(0,1);
\draw[#1,<->,>=latex](-0.8,-0.4)--++(0,0.8);
}
% commande \prisme{position}{background}.
\newcommand{\prisme}[2]
{
\draw[#1,#2](60:1)--(180:1)--(300:1)--cycle;
\draw[#1](60:1)--(-60:1);
}