请修改以下代码,添加新命令以\marks{7,6,4,3}
获取
\documentclass{article}
\usepackage{amsmath}
\usepackage{enumerate}
\usepackage{graphics}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzstyle{NP}=[rectangle,
draw=blue!80,
rounded corners=1pt,
inner sep=12pt,
inner ysep=4pt,
draw, fill=black!0,
text width=2cm,
minimum height=.9cm]
\newcommand{\TS}[1]{
\begin{tikzpicture}
\node[rectangle,draw=blue!80,rounded corners=1pt,inner sep=60pt, inner ysep=16pt, minimum height=6cm, text width=10cm,align=center,]
{
\begin{enumerate}[]
\itemsep.1em
\item
\foreach \x in {1, ...,#1}{\item{
\begin{tikzpicture}
\node[NP, fill=black!05](abc){\bfseries \x};
\node[NP, right=of abc]{};
\end{tikzpicture}
}}%
\end{enumerate}
};
\end{tikzpicture}
}
\begin{document}
%\marks{7,6,4,3}
\TS{4}
\end{document}
答案1
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning}
\newcommand{\ts}[1]{
\begin{tikzpicture}[box/.style={draw, rounded corners, minimum width=15mm, minimum height=6mm}]
\foreach \i [count=\ni] in {#1}{
\node[box] at (0,-\ni) (l\ni) {\ni};
\node[box, text=red, font=\bfseries, right= 3mm of l\ni] (r\ni) {\i};}
\end{tikzpicture}}
\begin{document}
\ts{7,3,4,6}
\ts{2,3,4}
\ts{5,6,8,9,10}
\end{document}
答案2
这一想法的基本来源是这帖子。请注意,您需要该listofitems
软件包,您可以下载这里。我只是想扩展 的定义,\TS
以便第二个参数可以通过 读取\readlist
。然后,您只需创建一个名为 的列表\mark
,它可以通过索引访问。
\documentclass{article}
\usepackage{amsmath}
\usepackage{enumerate}
\usepackage{graphics}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{listofitems}
\tikzstyle{NP}=[rectangle,
draw=blue!80,
rounded corners=1pt,
inner sep=12pt,
inner ysep=4pt,
draw, fill=black!0,
text width=2cm,
minimum height=.9cm]
\newcommand{\TS}[2]{%
\readlist*\mark{#2}
\begin{tikzpicture}
\node[rectangle,draw=blue!80,rounded corners=1pt,inner sep=60pt, inner ysep=16pt, text width=10cm,align=center]
{
\begin{enumerate}[]
\itemsep.1em
\item
\foreach \x in {1, ...,#1}{\item{
\begin{tikzpicture}
\node[NP, fill=black!05](abc){\bfseries \x};
\node[NP, right=of abc]{\mark[\x]};
\end{tikzpicture}
}}%
\end{enumerate}
};
\end{tikzpicture}
}
\begin{document}
\TS{4}{7,6,4,3}
\end{document}