tikz:如何将节点中的鸭子包装成几行

tikz:如何将节点中的鸭子包装成几行

我想用几行来排列节点内的 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}

我尝试在鸭子之间放置\\\newline,,\linebreak但是没有成功: 在此处输入图片描述 如何在节点中绘制 4×5 只鸭子?

答案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}

在此处输入图片描述

相关内容