调用/插入 tcolorbox 数组的变量

调用/插入 tcolorbox 数组的变量

感谢 Tex 社区和 Stack Exchange。嗨,朋友们,

在@marmot先生的支持下,我可以在文件myarrays.tex中创建“变量数组”。链接主题:全局变量数组

现在我想为 templateA.tex 的 tcolorbox 调用/插入 myarrays.tex 的一些变量

Marmot先生的MWE:

 \documentclass[a4paper,twoside,12pt]{article}
\usepackage{tcolorbox}
\usepackage{filecontents}
\begin{filecontents*}{myarrays.tex}
\def\ArrayNames{{"koala","duck","marmot","penguin","bear"}}
\def\ArrayColors{{"gray","yellow","blue","red","brown","green!30!white","blue!75!black"}}
\end{filecontents*}
\usepackage{pgffor}
\usepackage{xcolor}
\begin{document}
\input{myarrays.tex}
\pgfkeys{/pgf/declare function={mymap(\x)=int(mod(1+\x*\x,4));}}
\begin{enumerate}
\foreach \X in \ArrayNames
{\foreach \Y [count=\Z starting from 0]in \X 
{\pgfmathsetmacro{\mycolor}{\ArrayColors[mymap(\Z)]}
\pgfmathsetmacro{\myname}{\ArrayNames[\Z]}
\item \textcolor{\mycolor}{\myname}}}
\end{enumerate}
\input{myarrays.tex} \pgfmathsetmacro{\myname}{\ArrayNames[3]} \myname

\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black,title=\color{white}\textbf{My Heading}]
    This is a \textbf{tcolorbox}.
    \tcblower
    Here. In the box
    \end{tcolorbox}
    \end{document}

现在,请指导我。我想使用数组变量在 tcolorbox 中进行更改:

1/ 标题 = Arrayname (2) = \color{white}\textbf{Marmot} (旧标题 = 我的标题)

2/ colback = \ArrayColors (5) = “绿色!30!白色”

3/ colframe = \ArrayColors (6) = "蓝色!75!黑色"

预先感谢。

答案1

您已经有该循环,因此只需要包含变量。

顺便说一句:由于您的文件仅包含\defs,因此将其包含两次是没有意义的。

盒子

\documentclass[a4paper,twoside,12pt]{article}
\usepackage{tcolorbox}
\usepackage{filecontents}
\begin{filecontents*}{myarrays.tex}
\def\ArrayNames{{"koala","duck","marmot","penguin","bear"}}
\def\ArrayColors{{"gray","yellow","blue","red","brown","green!30!white","blue!75!black"}}
\end{filecontents*}
\usepackage{pgffor}
\usepackage{xcolor}
\begin{document}
\input{myarrays.tex}
\pgfkeys{/pgf/declare function={mymap(\x)=int(mod(1+\x*\x,4));}}
\begin{enumerate}
\foreach \X in \ArrayNames
{\foreach \Y [count=\Z starting from 0]in \X 
{\pgfmathsetmacro{\mycolor}{\ArrayColors[mymap(\Z)]}
\pgfmathsetmacro{\myname}{\ArrayNames[\Z]}
\item \textcolor{\mycolor}{\myname}}}
\end{enumerate}

\foreach \X in \ArrayNames
{\foreach \Y [count=\Z starting from 0]in \X 
{\pgfmathsetmacro{\mycolback}{\ArrayColors[5]}
\pgfmathsetmacro{\mycolframe}{\ArrayColors[6]}
\pgfmathsetmacro{\myname}{\ArrayNames[\Z]}
\begin{tcolorbox}[colback=\mycolback,colframe=\mycolframe,title=\color{white}\textbf{\myname}]
    This is a \textbf{tcolorbox}.
    \tcblower
    Here. In the box
\end{tcolorbox}
}}

\end{document}

相关内容