1

I have a problem that is doing my head in, I am trying to color a graph with the color "Mahogany", thing that works when writting in a beamer but that suddently happens to stop working in an article. First latex tells me that it does not recognise the color. So, I tried to fix this by using the package \usepackage[dvipsnames]{xcolor} but then it comes up with an error saying that the option [dvipsnames] is not compatible with xcolor, weird since I have followed the instructions from the overleaf webpage.

I am attaching pictures and code if somebody could help me.

\usepackage[dvipsnames]{xcolor}
\begin{center}
    \begin{figure}
    \centering
        \begin{tikzpicture}
            \begin{axis}[
                xscale=1, yscale=1,
                width=10cm,
                domain= -4:4,
                xmin = -3, xmax = 3, ymin = 0, ymax = 1.2,
                xtick = {-0.707,0,0.707},
                ytick = {1},
                xticklabels = {\footnotesize $-\sqrt{\frac{1}{2}}$, \footnotesize $0$, \footnotesize $\sqrt{\frac{1}{2}}$},
                % yticklabels = {\footnotesize $f(a)$, \footnotesize $\tiny(1-\lambda)f(a)+\lambda f(b)$, \footnotesize $f\left( (1-\lambda)a+\lambda b\right)$,\footnotesize $f(b)$},
                axis lines = middle,
                % axis line style={draw=none},
                samples=100,
                no markers]
                \draw[dashed,gray, ultra thin] (.707, 0)--(.707, .607) ;
                \draw[dashed,gray, ultra thin] (-.707, 0)--(-.707, .607) ;
                \draw[dashed,gray, ultra thin] (3.24, 0)--(3.24, 3.5) ;
                \draw [decorate,decoration={brace,amplitude=5pt},xshift=0pt,yshift=2pt] (0.4,2.28) -- (1,2.28) node [black,midway,yshift=10pt] {\tiny $(x_1^*-\epsilon,x_1^*+\epsilon) = S $};
                \addplot[ultra thick, color=mahogany]{exp(-x^2)};
                \draw[dashed,gray, ultra thin] (.4, 2.3)--(1, 2.3);
            \end{axis}
        \end{tikzpicture}
    \end{figure}
\end{center}

KR enter image description here

  • 1
    The M in Mahogany has to be uppercase. If I change mahogany to Mahogany and wrap your center environment into \documentclass{article} \usepackage[dvipsnames]{xcolor} \usepackage{pgfplots} \pgfplotsset{compat=1.16} \begin{document} and \end{document}, it works. – Schrödinger's cat Sep 23 at 17:04
  • You can also wrap it into \PassOptionsToPackage{dvipsnames}{xcolor} \documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.16} \begin{document} and \end{document} but really the issue seems to be that you were using a lower-case m. – Schrödinger's cat Sep 23 at 17:09
  • Not sure exactly what error you got at the end there, but note that if you do \usepackage{tikz} \usepackage[dvipsnames]{xcolor} in that order, you'll get an error about an option clash. See e.g. tex.stackexchange.com/q/51488 Swap the order as in Schrödinger Cat's first comment, or use \PassOptionsToPackage as in his second comment. – Torbjørn T. Sep 23 at 18:20
  • Thank you very much for your attention, I have included all of that, although some characteristics change for example: \documentclass[12pt,letterpaper]{article} I don't know if this is really important or not. On top of that when I include \usepackage[dvipsnames]{xcolor} it comes up with a message of "Latex error: Option clash for a package xcolor" This might help more. Thank you very much!!! – Rubén Pérez Sanz Sep 23 at 22:46
  • 4
    I'm voting to close this question because it is solved in the comments. – Stefan Pinnow Sep 26 at 18:36