我正在用 fancytikzposter 包制作一张海报,我剪掉了有问题的部分,可以从这里下载这里。
我在海报里创建了一个 tikzpicture,但出现了一些问题:
- 标签是黑色的,我想把它们的颜色改成白色,但我不知道该怎么做
- 标签距离其所属的节点较远,我想将它们移近节点
- 还有一个额外内容(但不太重要):是否可以在第二行镜像标签的框架(当标签位于节点下方时)?
这是属于上述 tikzpicture 的代码
\tikzstyle{input} = [draw, rectangle, rounded corners]
\begin{tikzpicture}[node distance=0.26\textwidth,>=latex', line width=4pt,anchor=south]
\node [input, label={original} ] (signOrig) { \includegraphics[width=.14\textwidth]{Erika2b} };
\node [input, label={grayscale}, right of=signOrig] (signGr) { \includegraphics[width=.14\textwidth]{Erika2b} };
\node [input, label={binary}, right of=signGr] (signBin) { \includegraphics[width=.14\textwidth]{Erika_segm} };
\node [input, label=below:{edges}, below of=signBin, node distance=0.3\textwidth] (signGray) { \includegraphics[width=.14\textwidth]{Erika2_edgeb} };
\node [input, label=below:{segmented}, left of=signGray] (signDilate) { \includegraphics[width=.14\textwidth]{Erika_segm}};
\node [input, label=below:{centerline}, left of=signDilate] (signBw) { \includegraphics[width=.14\textwidth]{Erika_skel}};
\draw [->] (signOrig) -- (signGr);
\draw [->] (signGr) -- (signBin);
\draw [->] (signBin) -- (signGray);
\draw [->] (signGray) -- (signDilate);
\draw [->] (signDilate) -- (signBw);
\end{tikzpicture}
答案1
问题是label
s 也是节点,并且 fancytikzposter 似乎定义了一个默认节点形状,该形状在任何地方(甚至在标签中)都使用,它有两部分,一个在上方用于“标题”,另一个在下方用于“内容”。
当您编写label={foo}
一个节点时,会以“foo”作为标题,以空白作为内容。正是这个空白在标签和节点之间产生了额外的距离。对于底部的节点,空白位于标签下方,因此不太容易注意到它。
如果您为标签定义适当的样式(例如my label
),使用rectangle
形状而不是 fancytikzposter 使用的默认两部分,然后在每个标签中指定该样式,则可以解决此问题。此外,您可以准备此样式以使用白色。例如:
\tikzset{my label/.style = {
node distance=0pt, inner sep=8mm,
anchor=south,
rectangle, rounded corners=8mm,
white, fill=blocktitlefillcolor,
}
}
然后:
\node [input, label={[my label]original}] (signOrig) { \includegraphics[width=.14\textwidth]{Erika2b} };
\node [input, label={[my label]grayscale}, right of=signOrig] (signGr) { \includegraphics[width=.14\textwidth]{Erika2b} };
\node [input, label={[my label]binary}, right of=signGr] (signBin) { \includegraphics[width=.14\textwidth]{Erika_segm} };
\node [input, label={[my label]below:edges}, below of=signBin, node distance=0.3\textwidth] (signGray) { \includegraphics[width=. → 14\textwidth]{Erika2_edgeb} };
\node [input, label={[my label]below:segmented}, left of=signGray] (signDilate) { \includegraphics[width=.14\textwidth]{Erika_segm}};
\node [input, label={[my label]below:centerline}, left of=signDilate] (signBw) { \includegraphics[width=.14\textwidth]{Erika_skel}};
这将产生(我将海报裁剪到相关部分):
但请注意,您得到的是一个“完整”的圆角矩形,而不是您显然想要的半矩形。要伪造这种半矩形,您可以采用不同的方法。而不是label
,使用普通节点(也是预定义样式),在背景中绘制并略低于所包含的图像。以下代码实现了这个想法:
\usetikzlibrary{shapes,arrows,positioning,backgrounds}
% ...
\tikzstyle{input} = [draw, rectangle, rounded corners, fill=white]
\tikzset{my label/.style = {
node distance=0pt,
inner sep=12mm,
rectangle,
rounded corners=8mm,
white,
fill=blocktitlefillcolor,
}
}
% ...
\begin{tikzpicture}[node distance=0.26\textwidth,>=latex', line width=4pt,anchor=south]
\node [input ] (signOrig) { \includegraphics[width=.14\textwidth]{Erika2b} };
\node [input, right of=signOrig] (signGr) { \includegraphics[width=.14\textwidth]{Erika2b} };
\node [input, right of=signGr] (signBin) { \includegraphics[width=.14\textwidth]{Erika_segm} };
\node [input, below of=signBin, node distance=0.3\textwidth] (signGray) { \includegraphics[width=.14\textwidth]{Erika2_edgeb} };
\node [input, left of=signGray] (signDilate) { \includegraphics[width=.14\textwidth]{Erika_segm}};
\node [input, left of=signDilate] (signBw) { \includegraphics[width=.14\textwidth]{Erika_skel}};
\begin{pgfonlayer}{background}
\node [my label, above=-8mm of signOrig] {original};
\node [my label, above=-8mm of signGr] {grayscale};
\node [my label, above=-8mm of signBin] {binary};
\node [my label, below=-8mm of signBw] {centerline};
\node [my label, below=-8mm of signDilate] {segmented};
\node [my label, below=-8mm of signGray] {edges};
\end{pgfonlayer}
\draw [->] (signOrig) -- (signGr);
\draw [->] (signGr) -- (signBin);
\draw [->] (signBin) -- (signGray);
\draw [->] (signGray) -- (signDilate);
\draw [->] (signDilate) -- (signBw);
\end{tikzpicture}
结果是:
而且在我看来,代码也更容易阅读。