问题
是否可以将\item
命令保留在主体中,并使用包中的命令包装itemize
列表环境?我还尝试将列表包装在 TikZ 节点中,该节点也包装在\NewEnviron
environ
minipage
:) 中,我知道这是可能的这里。
目的
保持源代码尽可能简单。
示例代码
\documentclass{article}
\usepackage{fontspec}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\usepackage{environ} % \NewEnviron command collects body and can be accessed by \BODY macro within the definition for making custom environments
\NewEnviron{RedBoxList}[1][MISSING VARIABLE!]{%
\begin{tikzpicture}[remember picture, overlay]
\path [fill=red] (current page.north west) rectangle (current page.north);
\node [xshift=5mm,yshift=-10mm,anchor=north west, align=left] (nodeID) at (current page.north west) {%
\begin{minipage}[t]{.6\linewidth}
\textcolor{white}{%
{\Huge #1}
\begin{itemize}
\BODY
\end{itemize}
}% end textcolor white
\end{minipage}
};% end node
\end{tikzpicture}
}% end NewEnviron
\begin{document}
\begin{RedBoxList}{Title of the Box}
\item test1
\item test2
\item test3
\end{RedBoxList}
\end{document}
答案1
你正在定义RedBoxList
使用选修的参数,不是强制性的,所以
\begin{RedBoxList}[Title of the Box]
\item test1
\item test2
\item test3
\end{RedBoxList}
将会做你想让它做的事。
但是,它似乎是一个糟糕的用户界面:忘记可选参数将导致标题为“缺少变量!”,因此最好将此参数作为必需的进行管理:
\NewEnviron{RedBoxList}[1]{%
<same code as before>
}
答案2
您需要声明Title of The Box
参数。我将其更改为[2]
这意味着它不使用可选参数#1
,但我不知道您打算将其用于何处
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\usepackage{environ} % \NewEnviron command collects body and can be accessed by \BODY macro within the definition for making custom environments
\NewEnviron{RedBoxList}[2][MISSING VARIABLE!]{%
\begin{tikzpicture}[remember picture, overlay]
\path [fill=red] (current page.north west) rectangle (current page.north);
\node [xshift=5mm,yshift=-10mm,anchor=north west, align=left] (nodeID) at (current page.north west) {%
\begin{minipage}[t]{.6\linewidth}%\show\BODY
\textcolor{white}{%
{\Huge #2}
\begin{itemize}
\BODY
\end{itemize}
}% end textcolor white
\end{minipage}
};% end node
\end{tikzpicture}
}% end NewEnviron
\begin{document}
\begin{RedBoxList}{Title of the Box}
\item test1
\item test2
\item test3
\end{RedBoxList}
\end{document}