加载 xcolor 时应该将 PassOptionsToPackage 放在哪里?

加载 xcolor 时应该将 PassOptionsToPackage 放在哪里?

我正在尝试根据以下数据从表格中绘制图表:

DIM AVRG1 MAX1 MIN1 AVRG2 MAX2 MIN2

所以我想在图表中画 6 条线:

  • 2 表示
  • 2 表示最大值
  • 2 表示最小值

此外,我想用更深的颜色(如蓝色和红色)来“标记”平均值,并赋予另外两种不太强烈的颜色,例如青色或橙色。

所以我包括

\usepackage{tikz}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}

让 tikz 负责加载 xcolor 我传递给它以下选项:

\PassOptionsToPackage{usenames,dvipsnames}{xcolor}

如果我尝试单独加载 xcolor 我会收到错误,但这种方式却可以正常工作。

然后我通过以下方式从文件中获取值:

\begin{tikzpicture}
    \begin{axis}[width=\linewidth, xmin=0, xmax=8192, ymin=0]
        \addplot [thick, blue] table [mark=none, y=AVRG1, x=DIM]{time1-CPU.data};
        \addplot [small, cyan]table [mark=none, y=MAX1, x=DIM]{time1-CPU.data};
    \end{axis}
\end{tikzpicture}

这确实有效,因为青色在 tikz [2] 中。但是,假设我想使用 xcolor [1] 中的 Cerulean 而不是青色,那么我会收到以下错误:

 Package pgfkeys Error: I do not know the key '/tikz/Cerulean' and I am going to ignore it. Perhaps you misspelled it

我该如何让它工作?谢谢!

编辑:这是一个例子

\documentclass[epsfig,a4paper,11pt,titlepage,twoside,openany]{book}
\usepackage{epsfig}
\usepackage{plain}
\usepackage{setspace}
\usepackage[paperheight=29.7cm,paperwidth=21cm,outer=1.5cm,inner=2.5cm,top=2cm,bottom=2cm]{geometry} 
\usepackage{titlesec}

\usepackage[utf8x]{inputenc} 

\singlespacing

\usepackage[italian]{babel}

\usepackage{ulem} 
\usepackage{amsmath} 
\usepackage{array}
\usepackage{multirow} 
\setcounter{secnumdepth}{5} 
\usepackage{caption}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\usepackage{pgfmath}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true, linktocpage=true, pdfstartpage=1, pdfstartview=FitV,
    breaklinks=true, pdfpagemode=UseNone, pageanchor=true, pdfpagemode=UseOutlines,
    plainpages=false, bookmarksnumbered, bookmarksopen=true, bookmarksopenlevel=1,
    hypertexnames=true, pdfhighlight=/O,
    urlcolor=black, linkcolor=black, citecolor=black,
} 
\PassOptionsToPackage{usenames,dvipsnames}{xcolor}

\usepackage{tikz}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usetikzlibrary{arrows,automata}
\usegdlibrary{trees}

\usepackage{listings}
\usepackage[cache=false]{minted} 
\setminted{tabsize=4, breaklines, breakanywhere, linenos, mathescape, fontsize=\small}

\definecolor{Ashgrey}{rgb}{0.7, 0.75, 0.71}
\definecolor{Atompurple}{rgb}{0.6, 0.4, 0.8}

\begin{document}
\lstset{
      breakatwhitespace=false,         
      breaklines=true,     
      basicstyle=\footnotesize\ttfamily,            
      commentstyle=\color{Ashgey}, 
      keywordstyle=\color{Atompurple}, 
      language=C++, 
      rulecolor=\color{black}, 
      tabsize=4,
      escapeinside={\%*}{*)},
      morekeywords={compute, from, throw, std, ostringstream, __LINE__, __FILE__, define},
}

  \pagenumbering{gobble} 

  \clearpage
  \clearpage
  \pagestyle{plain} 
  \mainmatter

    \begingroup
      \renewcommand{\cleardoublepage}{} 
      \renewcommand{\clearpage}{} 
      \titleformat{\chapter}
        {\normalfont\Huge\bfseries}{\thechapter}{1em}{}

      \titlespacing*{\chapter}{0pt}{0.59in}{0.02in}
      \titlespacing*{\section}{0pt}{0.20in}{0.02in}
      \titlespacing*{\subsection}{0pt}{0.10in}{0.02in}
      \newcommand{\myparagraph}[1]{\paragraph{#1}\mbox{}\\}

      \begin{center}
        \begin{tikzpicture}
            \begin{axis}[width=\linewidth, xmin=0, xmax=8192, ymin=0, xlabel=\# Clotoidi, ylabel=Tempo medio ($ms$)]
                \addplot [thick, draw=blue] table [mark=none, y=AVRG, x=DIM]{time1-CPU.data};
                \addplot [small, cyan]table [mark=none, y=MAX, x=DIM]{time1-CPU.data};
                \addplot [small, color=Cerulean]table [mark=none, y=MIN, x=DIM]{time1-CPU.data};
            \end{axis}
        \end{tikzpicture}
        \end{center}

    \endgroup



    \titleformat{\chapter}
        {\normalfont\Huge\bfseries}{Allegato \thechapter}{1em}{}
    \appendix

\end{document}

我把所有包裹都留在里面,因为我不知道它们是否会与另一个包裹发生冲突(?)。

编译后得到:

Package xcolor Error: Undefined color `Cerulean'.

Package xcolor Error: Undefined color `tikz@color'.

[1]https://en.wikibooks.org/wiki/LaTeX/Colors

[2]https://en.wikibooks.org/wiki/LaTeX/PGF/TikZ#Color

答案1

Cerulean下面是一个可以很好地显示效果的示例:

在此处输入图片描述

代码:

\PassOptionsToPackage{usenames,dvipsnames}{xcolor}
\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}

\begin{document}
\noindent
\begin{tikzpicture}
    \begin{axis}
        \addplot [thick, red,      mark=none] {x+3};
        \addplot [thick, Cerulean, mark=none] {-2*x-4};
    \end{axis}
\end{tikzpicture}
\end{document}

答案2

您可以在开始时定义自己的颜色

\definecolor{Blue}{rgb}{0.0,0.0,0.7}
\definecolor{Red}{rgb}{0.7,0.0,0.0}
\definecolor{Green}{rgb}{0.0,0.5,0.0}
\definecolor{Gray}{gray}{0.85}
\definecolor{LightCyan}{rgb}{0.88,1,1}
\definecolor{White}{rgb}{1,1,1}

相关内容