我想用几行来排列节点内的 tikz 鸭子:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{ducks}
\begin{document}
\begin{tikzpicture}[
BOX/.style = {draw=orange,rectangle,fill=orange!20,minimum height=5cm, minimum width=4cm, inner sep=0,rounded corners=5pt,dashed,line width=1pt}
]
\def\DUCKFIVE{% TO PUT DUCKS IN NODES
\begin{tikz}
\tikz\shuffleducks\duck[\randomhead,scale=0.3];
\tikz\shuffleducks\duck[\randomhead,scale=0.3,xshift=1cm];
\tikz\shuffleducks\duck[\randomhead,scale=0.3,xshift=2cm];
\tikz\shuffleducks\duck[\randomhead,scale=0.3,xshift=-1cm];
\tikz\shuffleducks\duck[\randomhead,scale=0.3,xshift=-2cm];
\end{tikz}
}
\node[BOX=orange!30](TREE){
\DUCKFIVE
\\
\DUCKFIVE
\newline
\DUCKFIVE
\linebreak
\DUCKFIVE
};
\end{tikzpicture}
\end{document}
答案1
嵌套 tikzpictures 通常不是一个好主意。我建议改用 tikz 矩阵:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{ducks,backgrounds}
\begin{document}
\begin{tikzpicture}
\matrix {
\shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; \\
\shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; \\
\shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; \\
\shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; \\
\shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; \\
};
\begin{scope}[on background layer]
\path[draw=orange,rectangle,fill=orange!20,minimum height=5cm, minimum width=4cm, inner sep=0,rounded corners=5pt,dashed,line width=1pt] (current bounding box.south west) rectangle (current bounding box.north east);
\end{scope}
\end{tikzpicture}
\end{document}
包含标题:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{ducks,backgrounds,positioning}
\begin{document}
\begin{tikzpicture}
\node (a) at (0,0) {some title above};
\matrix[below=0cm of a] {
\shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; \\
\shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; \\
\shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; \\
\shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; \\
\shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; & \shuffleducks\pic[/duck/\randomhead,scale=0.3] {duck}; \\
};
\begin{scope}[on background layer]
\path[draw=orange,rectangle,fill=orange!20,minimum height=5cm, minimum width=4cm, inner sep=0,rounded corners=5pt,dashed,line width=1pt] (current bounding box.south west) rectangle (current bounding box.north east);
\end{scope}
\end{tikzpicture}
\end{document}