我之前曾在此论坛中询问过如何绘制彩色位串矩形链。我最终使用了以下代码:
\begin{tikzpicture}[
node distance = 1 pt,
start chain = going right,
mpnv/.style args = {#1/#2/#3}{% multi part node vertical % <---
rectangle split, rectangle split parts=3,
minimum width=1em, inner ysep=1pt,
font = \sffamily,
node contents = {\nodepart{one} #1
\nodepart{two} #2
\nodepart{three}#3},
on chain},
E/.style = {fill=red!30},
O/.style = {fill=cyan!30},
I/.style = {fill=yellow!30},
V/.style = {fill=green!30},
L/.style = {fill=olive!30}
]
\node[mpnv=A/B/C];
\node[E, mpnv=1/0/0];
\node[O, mpnv=1/1/0];
\node[I, mpnv=0/1/0];
\node[I, mpnv=0/1/0];
\node[V, mpnv=1/1/1];
\node[L, mpnv=0/0/0];
\end{tikzpicture}
产生这个输出。
我正在尝试为位串树制作类似的图表。树的结构如下所示:
在乳胶中,用颜色简单地书写这段文字的方法是什么?
答案1
对于树我将使用forest
包:
\documentclass[border=3.141592]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta,
shapes.multipart}
\newcommand\mpn[3]{\nodepart{one} #1
\nodepart{two} #2
\nodepart{three} #3}
\newcommand\rsp{rectangle split parts}
\begin{document}
\tikzset{every label/.style = {font=\footnotesize\sffamily\bfseries}}
\begin{forest}
for tree = {
rectangle split,
rectangle split parts=3,
draw,
rectangle split draw splits=false,
inner ysep=2pt,
%
parent anchor=south,
child anchor=north,
edge = {semithick},
l sep=7mm,
s sep=5mm,
}
[\mpn{0}{1}{0}, fill=red!30
[\mpn{1}{1}{0}, fill=orange!30
[\mpn{1}{0}{0}, fill=cyan!30]
[\mpn{1}{0}{1}, fill=teal!30]
]
[\mpn{1}{1}{1}, fill=orange!30
[\mpn{0}{0}{1}, fill=teal!30]
[\mpn{0}{1}{1}, fill=cyan!30]
]
]
\end{forest}
\end{document}
如您所见,我没有考虑节点的颜色。您可以/应该根据自己的意愿更改它们。