The following example defines colors enum1
, enum2
, ... using \colorlet
of package xcolor
. Then it hooks into \labelenumi
to add the color command with the color that consists of the value of counter enumi
. For deeper nesting levels of the enumerate
environment, \labelenumii
upto \labelenumiv
can also be changed accordingly.
\documentclass{article}
\usepackage{xcolor}
\colorlet{enum1}{green}
\colorlet{enum2}{orange}
\colorlet{enum3}{red}
\makeatletter
\newcommand*{\IfColorUndefined}[1]{%
\begingroup
\escapechar=`\\ %
\expandafter\expandafter\expandafter
\endgroup
\expandafter\ifx\csname\string\color @#1\endcsname\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\makeatother
\usepackage{etoolbox}
\preto\labelenumi{%
\IfColorUndefined{enum\the\value{enumi}}{}{%
\color{enum\the\value{enumi}}%
}%
}
\begin{document}
\begin{enumerate}
\item First
\item Second
\item Third
\end{enumerate}
\end{document}
![Result](https://i.stack.imgur.com/uCQbJ.png)
Extension for nested lists:
\documentclass{article}
\usepackage{xcolor}
\colorlet{enum1}{green}
\colorlet{enum2}{orange}
\colorlet{enum3}{red}
\makeatletter
\newcommand*{\IfColorUndefined}[1]{%
\begingroup
\escapechar=`\\ %
\expandafter\expandafter\expandafter
\endgroup
\expandafter\ifx\csname\string\color @#1\endcsname\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\makeatother
\usepackage{etoolbox}
\newcommand*{\DefColorListLabel}[1]{%
\expandafter\preto\csname label#1\endcsname{%
\IfColorUndefined{enum\the\value{#1}}{}{%
\color{enum\the\value{#1}}%
}%
}%
}
\DefColorListLabel{enumi}
\DefColorListLabel{enumii}
\DefColorListLabel{enumiii}
\DefColorListLabel{enumiv}
\begin{document}
\begin{enumerate}
\item First
\item Second
\item Third\label{third}
\item Fourth
\begin{enumerate}
\item Nested first
\item Nested second
\item Nested third\label{nestedthird}
\item Nested fourth
\end{enumerate}
\end{enumerate}
References: \ref{third} and \ref{nestedthird}.
\end{document}
![Result nested](https://i.stack.imgur.com/eeRuW.png)
The following code solves the plotting problem for tables like the one in your example. The solution applies \addplot
twice for each point: once for the fill and another time for the draw colour.
\documentclass[10pt,a4paper,landscape]{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\pgfplotstableread[row sep = \\]{
X Y C1 C2 Mark \\
1 1 0 6 * \\
2 2 6 0 otimes* \\
3 1 0 0 square* \\
4 5 6 6 diamond* \\
}\thetable
\pgfplotstablegetrowsof{\thetable}
\pgfmathsetmacro{\rowsminus}{\pgfplotsretval-1}
\foreach \i in {0,...,\rowsminus} {
\pgfplotstablegetelem{\i}{X}\of\thetable
\pgfmathsetmacro{\x}{\pgfplotsretval}
\pgfplotstablegetelem{\i}{Y}\of\thetable
\pgfmathsetmacro{\y}{\pgfplotsretval}
\pgfplotstablegetelem{\i}{C1}\of\thetable
\pgfmathsetmacro{\fillcolor}{\pgfplotsretval}
\pgfplotstablegetelem{\i}{C2}\of\thetable
\pgfmathsetmacro{\drawcolor}{\pgfplotsretval}
\pgfplotstablegetelem{\i}{Mark}\of\thetable
\edef\mymarkshape{\pgfplotsretval}
\addplot[
scatter,
point meta = \fillcolor,
visualization depends on = {value \mymarkshape \as \markshape},
scatter/use mapped color = {color=mapped color, draw opacity=0},
scatter/@pre marker code/.append style = {/tikz/mark = \markshape},
] coordinates {
(\x,\y)
};
\addplot[
scatter,
point meta = \drawcolor,
visualization depends on = {value \mymarkshape \as \markshape},
scatter/use mapped color = {color=mapped color, fill opacity=0},
scatter/@pre marker code/.append style = {/tikz/mark = \markshape},
] coordinates {
(\x,\y)
};
}
\end{axis}
\end{tikzpicture}
\end{document}
![Picture produced by example code](https://i.stack.imgur.com/EU12P.png)
The following example code might help you solve the other part of the question, if I understood what you are after.
The code accepts metadata in another format: a string consisting of comma-separated "visualization classes" in column Meta
. Each class only affects one aspect of style (fill color, drawing color, or plot mark), but it would be easy to define more complex classes. If the style of some point should be left at the default settings, an unknown class name such as default
can be used as the Meta
value of the point.
I used the following sources of information:
\documentclass[10pt,a4paper,landscape]{article}
\usepackage{pgfplots}
\usepackage{etoolbox}
\usepackage{xstring}
\begin{document}
% Handler for metadata, ignores unknown strings
\newcommand{\mymetahandler}[1]{%
\IfStrEqCase{#1}{%
{A}{\pgfmathsetmacro{\fillcolor}{0}}%
{B}{\pgfmathsetmacro{\fillcolor}{6}}%
{a}{\pgfmathsetmacro{\drawcolor}{0}}%
{b}{\pgfmathsetmacro{\drawcolor}{6}}%
{aa}{\edef\mymarkshape{*}}%
{bb}{\edef\mymarkshape{otimes*}}%
{cc}{\edef\mymarkshape{square*}}%
{dd}{\edef\mymarkshape{diamond*}}%
}
}
\begin{tikzpicture}
\begin{axis}
\pgfplotstableread[row sep = \\]{
X Y Meta \\
1 1 A,b,aa \\
2 2 B,a,bb \\
3 1 A,a,cc \\
4 5 B,b,dd \\
}\thetable
\pgfplotstablegetrowsof{\thetable}
\pgfmathsetmacro{\rowsminus}{\pgfplotsretval-1}
\foreach \i in {0,...,\rowsminus} {
\pgfplotstablegetelem{\i}{X}\of\thetable
\pgfmathsetmacro{\x}{\pgfplotsretval}
\pgfplotstablegetelem{\i}{Y}\of\thetable
\pgfmathsetmacro{\y}{\pgfplotsretval}
% Default point style
\pgfmathsetmacro{\fillcolor}{0}
\pgfmathsetmacro{\drawcolor}{0}
\edef\mymarkshape{*}
% Call the handler for each comma-separated metadata item
\pgfplotstablegetelem{\i}{Meta}\of\thetable
\expandafter\forcsvlist\expandafter\mymetahandler\expandafter{\pgfplotsretval}
\addplot[
scatter,
point meta = \fillcolor,
visualization depends on = {value \mymarkshape \as \markshape},
scatter/use mapped color = {color=mapped color, draw opacity=0},
scatter/@pre marker code/.append style = {/tikz/mark = \markshape},
] coordinates {
(\x,\y)
};
\addplot[
scatter,
point meta = \drawcolor,
visualization depends on = {value \mymarkshape \as \markshape},
scatter/use mapped color = {color=mapped color, fill opacity=0},
scatter/@pre marker code/.append style = {/tikz/mark = \markshape},
] coordinates {
(\x,\y)
};
}
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
You might consider using the comment package for including/excluding environments. If you just change the text color the text can still be copy/pasted which might not be what you want.