我正在关注这个帖子我想在拼图的每一块上添加文字,文字位于中间。应该添加什么?代码如下:
\documentclass{standalone}
\usepackage{tikz}
\newcommand{\side}[1]{
(0.5,0.5) --
(0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
(0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
(0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
(0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
(1.0,#1*0.00)
}
\newcommand{\piece}[5][white]{
\fill[#1]
\side{#2}
[rotate around={90:(0.5,0.5)}] \side{#3}
[rotate around={180:(0.5,0.5)}] \side{#4}
[rotate around={270:(0.5,0.5)}] \side{#5}
-- cycle;
}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\piece[red]{1}{1}{0}{0}
\end{scope}
\begin{scope}[xshift=1cm]
\piece[blue]{1}{-1}{-1}{0}
\end{scope}
\begin{scope}[xshift=2cm]
\piece[green]{1}{0}{1}{0}
\end{scope}
\begin{scope}[yshift=-1cm]
\piece[green]{1}{-1}{0}{-1}
\end{scope}
\begin{scope}[xshift=1cm,yshift=-1cm]
\piece[red]{1}{-1}{1}{-1}
\end{scope}
\begin{scope}[xshift=2cm,yshift=-1cm]
\piece[blue]{-1}{0}{1}{-1}
\end{scope}
\begin{scope}[yshift=-2cm]
\piece[blue]{0}{-1}{0}{-1}
\end{scope}
\begin{scope}[xshift=1cm,yshift=-2cm]
\piece[green]{0}{-1}{1}{-1}
\end{scope}
\begin{scope}[xshift=2cm,yshift=-2cm]
\piece[red]{0}{0}{1}{1}
\end{scope}
\end{tikzpicture}
\end{document}
答案1
我在 中添加了一个额外的参数 ( #6
) \piece
,并将其添加到其定义的末尾”\node [white] at (.5,.5) {#6};
\documentclass{standalone}
\usepackage{tikz}
\newcommand{\side}[1]{
(0.5,0.5) --
(0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
(0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
(0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
(0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
(1.0,#1*0.00)
}
\newcommand{\piece}[6][white]{
\fill[#1]
\side{#2}
[rotate around={90:(0.5,0.5)}] \side{#3}
[rotate around={180:(0.5,0.5)}] \side{#4}
[rotate around={270:(0.5,0.5)}] \side{#5}
-- cycle;
\node [white] at (.5,.5) {#6};
}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\piece[red]{1}{1}{0}{0}{A}
\end{scope}
\begin{scope}[xshift=1cm]
\piece[blue]{1}{-1}{-1}{0}{B}
\end{scope}
\begin{scope}[xshift=2cm]
\piece[green]{1}{0}{1}{0}{C}
\end{scope}
\begin{scope}[yshift=-1cm]
\piece[green]{1}{-1}{0}{-1}{D}
\end{scope}
\begin{scope}[xshift=1cm,yshift=-1cm]
\piece[red]{1}{-1}{1}{-1}{E}
\end{scope}
\begin{scope}[xshift=2cm,yshift=-1cm]
\piece[blue]{-1}{0}{1}{-1}{F}
\end{scope}
\begin{scope}[yshift=-2cm]
\piece[blue]{0}{-1}{0}{-1}{G}
\end{scope}
\begin{scope}[xshift=1cm,yshift=-2cm]
\piece[green]{0}{-1}{1}{-1}{H}
\end{scope}
\begin{scope}[xshift=2cm,yshift=-2cm]
\piece[red]{0}{0}{1}{1}{I}
\end{scope}
\end{tikzpicture}
\end{document}
如果您希望能够添加更多文本,我建议调用 as \begin{tikzpicture}[scale=2]
(或其他值)。这将增加片段的大小,而不会改变叠加文本的大小。例如,使用比例 2,它看起来如下:
补充
根据 OP 的后续问题:如何获取大纲?如何添加更多文本?
有两件事需要更改。\fill[#1]
命令更改为\draw[#1,postaction={fill=gray!10}]
,并且内部\node
的颜色可能需要重新评估,此处为\node [black]
。
为了增加拼图块中的文本量,我使用了包\Centerstack
中的stackengine
。我还增大了scale=
的tikzpicture
,事后可以随时缩小。
\documentclass{standalone}
\usepackage{tikz,stackengine}
\setstackEOL{\\}
\newcommand{\side}[1]{
(0.5,0.5) --
(0.0,#1*0.00) .. controls (0.0,#1*0.00) and (0.4,#1*-0.04) ..
(0.4,#1*0.04) .. controls (0.4,#1*0.11) and (0.2,#1*0.26) ..
(0.5,#1*0.26) .. controls (0.8,#1*0.26) and (0.6,#1*0.11) ..
(0.6,#1*0.04) .. controls (0.6,#1*-0.04) and (1.0,#1*0.00) ..
(1.0,#1*0.00)
}
\newcommand{\piece}[6][white]{
\draw[#1,postaction={fill=gray!10}]
\side{#2}
[rotate around={90:(0.5,0.5)}] \side{#3}
[rotate around={180:(0.5,0.5)}] \side{#4}
[rotate around={270:(0.5,0.5)}] \side{#5}
-- cycle;
\node [black] at (.5,.5) {\Centerstack{#6}};
}
\begin{document}
\begin{tikzpicture}[scale=3.5]
\begin{scope}
\piece[red]{1}{1}{0}{0}{my text\\goes right\\here}
\end{scope}
\begin{scope}[xshift=1cm]
\piece[blue]{1}{-1}{-1}{0}{B}
\end{scope}
\begin{scope}[xshift=2cm]
\piece[green]{1}{0}{1}{0}{C}
\end{scope}
\begin{scope}[yshift=-1cm]
\piece[green]{1}{-1}{0}{-1}{D}
\end{scope}
\begin{scope}[xshift=1cm,yshift=-1cm]
\piece[red]{1}{-1}{1}{-1}{E}
\end{scope}
\begin{scope}[xshift=2cm,yshift=-1cm]
\piece[blue]{-1}{0}{1}{-1}{F}
\end{scope}
\begin{scope}[yshift=-2cm]
\piece[blue]{0}{-1}{0}{-1}{G}
\end{scope}
\begin{scope}[xshift=1cm,yshift=-2cm]
\piece[green]{0}{-1}{1}{-1}{H}
\end{scope}
\begin{scope}[xshift=2cm,yshift=-2cm]
\piece[red]{0}{0}{1}{1}{I}
\end{scope}
\end{tikzpicture}
\end{document}
答案2
您可以绘制包含如下文本的拼图碎片:
\documentclass{standalone}
\usepackage{jigsaw}
\tikzset{
every node/.style={draw},
foo/.style={draw=none,gray,xshift=0.5cm,yshift=0.5cm}
}
\begin{document}
\begin{tikzpicture}
\path (0,1) pic [fill=red] {piece={1}{1}{0}{0}} node[foo] {A};
\path (1,1) pic [fill=green] {piece={1}{0}{0}{-1}} node[foo] {B};
\path (0,0) pic [fill=blue] {piece={0}{-1}{-1}{0}} node[foo] {C};
\path (1,0) pic [fill=yellow] {piece={0}{0}{-1}{1}} node[foo] {D};
\end{tikzpicture}
\end{document}