我正在尝试从一篇论文中重新创建此图表以用于我的论文。我的想法是,我可以将其缩放到不同的大小,只使用其中的一部分并插入不同的节点,例如圆形和三角形。
我曾尝试重现它,但是我对 tikz 相当不熟悉,因此经过几个小时的拼命尝试让它工作后,我想出了一个庞大而又不雅观的解决方案,它看起来并不像我想要的那样。
\PassOptionsToPackage{svgnames}{xcolor}
\documentclass[12pt,a4paper]{scrartcl}
\usepackage{tikz, pgf}
\usepackage{xltxtra}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usetikzlibrary{
positioning,
shapes.geometric,
shapes.misc,
calc,
fit,
matrix}
\begin{document}
\begin{tikzpicture} [pics/myHexagon/.style args={#1/#2/#3}%
{
code=
{
\pgfmathsetmacro{\mySqrt}{sqrt(3)/2}
\def\r{#1}
\def\a{#2}
\def\c{#3}
\draw [cm={\r,0,.5*\r,\mySqrt*\r,(0,0)},fill=\c,text=white]
(1+\a,0) coordinate (-corner 0) coordinate (-corner 6)
-- (\a,1) coordinate (-corner 1)
-- (-1-\a,1) coordinate (-corner 2)
-- (-1-\a,0) coordinate (-corner 3)
-- (-\a,-1) coordinate (-corner 4)
-- (1+\a,-1) coordinate (-corner 5)
-- cycle;
{asfd}
}
}]
\draw (0,0) pic {myHexagon={.6/.3/RoyalBlue}};
\draw (2,0) pic {myHexagon={.6/.3/DarkMagenta}};
\draw (4,0) pic {myHexagon={.6/.3/RoyalBlue}};
\draw (6,0) pic {myHexagon={.6/.3/DarkMagenta}};
\draw (2,-1.5) node [shape=ellipse,draw,minimum height=1cm,fill=red] {L-Ala};
\draw (1,-3) node [shape=ellipse,draw,minimum height=1cm, fill=yellow] {D-Glu};
\draw (0,-4.5) node [shape=ellipse,draw,minimum height=1cm] {L-Lys};
\draw (0,-6) node [shape=ellipse,draw,minimum height=1cm] {D-Ala};
\draw (1.7,-4.5) node [shape=circle,draw,minimum height=.75cm] {Gly};
\draw (3,-4.5) node [shape=circle,draw,minimum height=.75cm] {Gly};
\draw (4.3,-4.5) node [shape=circle,draw,minimum height=.75cm] {Gly};
\draw (5.6,-4.5) node [shape=circle,draw,minimum height=.75cm] {Gly};
\draw (6.9,-4.5) node [shape=circle,draw,minimum height=.75cm] {Gly};
\draw (8.5,-4.5) node [shape=ellipse,draw,minimum height=1cm] {D-Ala};
\draw (7.5,-6) node [shape=ellipse,draw,minimum height=1cm] {L-Lys};
\draw (6.5,-7.5) node [shape=ellipse,draw,minimum height=1cm] {D-Glu};
\draw (5.5,-9) node [shape=ellipse,draw,minimum height=1cm] {L-Ala};
\draw (3.5,-10.5) pic {myHexagon={.6/.3/RoyalBlue}};
\draw (1.5,-10.5) pic {myHexagon={.6/.3/DarkMagenta}};
\draw (7.5,-10.5) pic {myHexagon={.6/.3/RoyalBlue}};
\draw (5.5,-10.5) pic {myHexagon={.6/.3/DarkMagenta}};
\end{tikzpicture}
\end{document}
有人能帮我简化并完成它吗?谢谢!
[编辑]
我应该提到我使用仅缩放 TikZ 多边形的一部分对于多边形。
答案1
我建议使用chamfered rectangle
表示六边形,并将 设置为较大的值chamfered rectangle xsep
。pgfmanual 在第 736 页写道
设置倒角水平延伸超出节点内容(包括内部分隔符)的距离。如果 ⟨length⟩ 很大,以至于顶部和底部的倒角边缘会交叉,则忽略 ⟨length⟩ 并绘制倒角边缘,使它们在中间相交。
并显示一个六边形。此外,您正在加载positioning
,我建议使用它进行相对定位。(您也可以研究链,但我个人认为这有时有点过头了。)所以这是第一个提议。
\PassOptionsToPackage{svgnames}{xcolor}
\documentclass[12pt,a4paper]{scrartcl}
\usepackage{tikz, pgf}
\usepackage{xltxtra}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usetikzlibrary{
positioning,
shapes.geometric,
shapes.misc,
shadows.blur,
calc}
\newcounter{hexa}
\begin{document}
\begin{tikzpicture}[my hexa/.style={blur shadow,chamfered rectangle,chamfered rectangle
xsep=2cm,draw,text=white,path picture={%
\draw[white] let \p1=($(path picture bounding box.north)-(path picture
bounding box.east)$) in
([xshift=-1pt]path picture bounding box.east)
-- ++(-\y1+1pt,\y1-1pt) -- ++(2*\x1,0);}},
my elli/.style={blur shadow,ellipse,draw,text=white,path picture={%
\fill[white] let \p1=($(path picture bounding box.north)-(path picture
bounding box.east)$) in ([xshift=-1pt]path picture bounding box.east)
to[out=90,in=0,looseness=0.8] ([yshift=-1pt]path picture bounding box.north)
to[out=0,in=90,looseness=0.7] cycle;
}},
shaded triangle/.style={blur shadow,regular polygon,regular polygon sides=3,shape border rotate=0,
inner sep=1pt,draw,inner color=#1!10,outer color=#1}]
\node[my hexa,fill=RoyalBlue] (Glc1) {GlcN Ac};
\node[right=of Glc1,my hexa,fill=DarkMagenta] (Mur1) {MurN Ac};
\node[right=of Mur1,my hexa,fill=RoyalBlue] (Glc2) {GlcN Ac};
\node[right=of Glc2,my hexa,fill=DarkMagenta] (Mur2) {MurN Ac};
%
\node[below=of Mur1,my elli,fill=DarkGreen] (L-Ala1) {L-Ala};
\node[below left=8mm and 5mm of L-Ala1,my elli,fill=purple] (D-Glu1)
{\textsc{d}-Glu};
\node[below left=8mm and 5mm of D-Glu1,my elli,fill=DarkRed] (L-Lys1)
{\textsc{l}-Lys};
\node[right=3mm of L-Lys1,my elli,fill=green!80!black] (Gly1) {Gly};
\node[right=3mm of Gly1,my elli,fill=green!80!black] (Gly2) {Gly};
\node[right=3mm of Gly2,my elli,fill=green!80!black] (Gly3) {Gly};
\node[right=3mm of Gly3,my elli,fill=green!80!black] (Gly4) {Gly};
\node[right=3mm of Gly4,my elli,fill=green!80!black] (Gly5) {Gly};
\node[right=3mm of Gly5,my elli,fill=cyan] (D-Ala1) {D-Ala};
\node[below=8mm of L-Lys1,my elli,fill=cyan] (D-Ala2) {D-Ala};
%
\node[below left=8mm and -5mm of D-Ala1,my elli,fill=DarkRed] (L-Lys2)
{\textsc{l}-Lys};
\node[below left=8mm and -5mm of L-Lys2,my elli,fill=purple] (D-Glu2)
{\textsc{d}-Glu};
\node[below left=8mm and -5mm of D-Glu2,my elli,fill=DarkGreen] (L-Ala2)
{L-Ala};
%
\node[below=of L-Ala2,my hexa,fill=DarkMagenta] (Mur3) {MurN Ac};
\node[left=of Mur3,my hexa,fill=RoyalBlue] (Glc3) {GlcN Ac};
\node[left=of Glc3,my hexa,fill=DarkMagenta] (Mur4) {MurN Ac};
\node[right=of Mur3,my hexa,fill=RoyalBlue] (Glc4) {GlcN Ac};
%
\draw (Glc1) -- (Mur1) -- (Glc2) -- (Mur2);
\draw (Glc2) -- (L-Ala1) -- (D-Glu1) -- (L-Lys1)
-- (Gly1) -- (Gly2) -- (Gly3) -- (Gly4) -- (Gly5)
-- (D-Ala1) -- (L-Lys2) -- (D-Glu2) -- (L-Ala2) -- (Mur3) --
(Glc3) -- (Mur4);
\draw (Mur3) -- (Glc4);
\draw (L-Lys1) -- (D-Ala2);
%
\node[above=5mm of Gly3,shaded triangle=red] (E4) {E4};
\draw[red,thick,-latex] (E4.south west) -- ($(Gly2)!0.5!(Gly3)$);
\draw[red,thick,-latex] (E4.south east) -- ($(Gly3)!0.5!(Gly4)$);
\path (Gly5) -- (D-Ala1) coordinate[midway](aux);
\node[anchor=south,shaded triangle=red] (E5) at (aux|-E4.south) {E5};
\draw[red,thick,-latex] (E5.south) -- (aux);
\node[right=2mm of D-Glu1] (txt1) {NH$_2$};
\node[left=2mm of D-Glu2] (txt2) {NH$_2$};
\draw (D-Glu1) -- (txt1);
\draw (D-Glu2) -- (txt2);
\end{tikzpicture}
\end{document}
为了使其变小,您可以缩放它(例如scale=0.8,transform shape
)和/或调整node distance
。
\PassOptionsToPackage{svgnames}{xcolor}
\documentclass[12pt,a4paper]{scrartcl}
\usepackage{tikz, pgf}
\usepackage{xltxtra}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usetikzlibrary{
positioning,
shapes.geometric,
shapes.misc,
shadows.blur,
calc}
\newcounter{hexa}
\begin{document}
\begin{tikzpicture}[node distance=3mm,scale=0.8,transform shape,
every shadow/.style={shadow xshift=-0.5ex,shadow yshift=-0.5ex},
my hexa/.style={blur shadow,chamfered rectangle,chamfered rectangle
xsep=2cm,draw,text=white,path picture={%
\draw[white] let \p1=($(path picture bounding box.north)-(path picture
bounding box.east)$) in
([xshift=-1pt]path picture bounding box.east)
-- ++(-\y1+1pt,\y1-1pt) -- ++(2*\x1,0);}},
my elli/.style={blur shadow,ellipse,draw,text=white,path picture={%
\fill[white] let \p1=($(path picture bounding box.north)-(path picture
bounding box.east)$) in ([xshift=-1pt]path picture bounding box.east)
to[out=90,in=0,looseness=0.8] ([yshift=-1pt]path picture bounding box.north)
to[out=0,in=90,looseness=0.7] cycle;
}},
shaded triangle/.style={blur shadow,regular polygon,regular polygon sides=3,shape border rotate=0,
inner sep=1pt,draw,inner color=#1!10,outer color=#1}]
\node[my hexa,fill=RoyalBlue] (Glc1) {GlcN Ac};
\node[right=of Glc1,my hexa,fill=DarkMagenta] (Mur1) {MurN Ac};
\node[right=of Mur1,my hexa,fill=RoyalBlue] (Glc2) {GlcN Ac};
\node[right=of Glc2,my hexa,fill=DarkMagenta] (Mur2) {MurN Ac};
%
\node[below=of Mur1,my elli,fill=DarkGreen] (L-Ala1) {L-Ala};
\node[below left=8mm and 5mm of L-Ala1,my elli,fill=purple] (D-Glu1)
{\textsc{d}-Glu};
\node[below left=8mm and 5mm of D-Glu1,my elli,fill=DarkRed] (L-Lys1)
{\textsc{l}-Lys};
\node[right=3mm of L-Lys1,my elli,fill=green!80!black] (Gly1) {Gly};
\node[right=3mm of Gly1,my elli,fill=green!80!black] (Gly2) {Gly};
\node[right=3mm of Gly2,my elli,fill=green!80!black] (Gly3) {Gly};
\node[right=3mm of Gly3,my elli,fill=green!80!black] (Gly4) {Gly};
\node[right=3mm of Gly4,my elli,fill=green!80!black] (Gly5) {Gly};
\node[right=3mm of Gly5,my elli,fill=cyan] (D-Ala1) {D-Ala};
\node[below=8mm of L-Lys1,my elli,fill=cyan] (D-Ala2) {D-Ala};
%
\node[below left=8mm and -2mm of D-Ala1,my elli,fill=DarkRed] (L-Lys2)
{\textsc{l}-Lys};
\node[below left=8mm and -2mm of L-Lys2,my elli,fill=purple] (D-Glu2)
{\textsc{d}-Glu};
\node[below left=8mm and -2mm of D-Glu2,my elli,fill=DarkGreen] (L-Ala2)
{L-Ala};
%
\node[below=of L-Ala2,my hexa,fill=DarkMagenta] (Mur3) {MurN Ac};
\node[left=of Mur3,my hexa,fill=RoyalBlue] (Glc3) {GlcN Ac};
\node[left=of Glc3,my hexa,fill=DarkMagenta] (Mur4) {MurN Ac};
\node[right=of Mur3,my hexa,fill=RoyalBlue] (Glc4) {GlcN Ac};
%
\draw (Glc1) -- (Mur1) -- (Glc2) -- (Mur2);
\draw (Glc2) -- (L-Ala1) -- (D-Glu1) -- (L-Lys1)
-- (Gly1) -- (Gly2) -- (Gly3) -- (Gly4) -- (Gly5)
-- (D-Ala1) -- (L-Lys2) -- (D-Glu2) -- (L-Ala2) -- (Mur3) --
(Glc3) -- (Mur4);
\draw (Mur3) -- (Glc4);
\draw (L-Lys1) -- (D-Ala2);
%
\node[above=5mm of Gly3,shaded triangle=red] (E4) {E4};
\draw[red,thick,-latex] (E4.south west) -- ($(Gly2)!0.5!(Gly3)$);
\draw[red,thick,-latex] (E4.south east) -- ($(Gly3)!0.5!(Gly4)$);
\path (Gly5) -- (D-Ala1) coordinate[midway](aux);
\node[anchor=south,shaded triangle=red] (E5) at (aux|-E4.south) {E5};
\draw[red,thick,-latex] (E5.south) -- (aux);
\node[right=2mm of D-Glu1] (txt1) {NH$_2$};
\node[left=2mm of D-Glu2] (txt2) {NH$_2$};
\draw (D-Glu1) -- (txt1);
\draw (D-Glu2) -- (txt2);
\draw (Glc1.west) -- ++ (-0.2,0) (Mur2.east) -- ++ (0.2,0)
(Glc4.east) -- ++ (0.2,0) (Mur4.west) -- ++ (-0.2,0);
\end{tikzpicture}
\end{document}
此最新版本还具有更逼真的阴影,与亮点相反。
答案2
替代解决方案,不那么花哨(但可以简单添加),具有节点的相对定位,并且经过一些努力使代码简短......
\documentclass[12pt,a4paper]{scrartcl}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[version=4]{mhchem}
\PassOptionsToPackage{svgnames}{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc, chains,
positioning,
shadows,
shapes.geometric, shapes.symbols
}
\makeatletter
\tikzset{suppress join/.code={\def\tikz@after@path{}}}
\makeatother
\begin{document}
\begin{tikzpicture}[
node distance = 8mm and 6mm,
start chain = going right,
HEX/.style = {signal, signal to=left and right,
signal pointer angle=120,
draw=#1, fill=#1!60, text=white,
minimum height=10mm, inner sep=-3pt,
drop shadow,
on chain, join=by -},
ELL/.style = {ellipse, draw=#1, fill=#1!60, text=white,
minimum height=8mm, drop shadow,
on chain, join=by -},
CIR/.style = {circle, draw=olive, ball color=olive!50,
minimum height=8mm, drop shadow,
on chain, join=by -},
TRI/.style = {isosceles triangle, draw=red, fill=red!60,
isosceles triangle apex angle=60,
shape border rotate=90}
]
\node (h11) [HEX=RoyalBlue] {GlcNAc};
\node (h12) [HEX=DarkMagenta] {MurNAc};
\node (h13) [HEX=RoyalBlue] {GlcNAc};
\node (h14) [HEX=DarkMagenta] {MurNAc};
\draw (h11.west) -- + (-0.5,0)
(h14.east) -- + ( 0.5,0);
%
\node (e11) [ELL=teal,suppress join,
below=of h12] {L-Ala};
\node (e12) [ELL=orange,
below left=of e11,
pin=right:\ce{NH2}] {D-Glu};
\node (e13) [ELL=teal, below left=of e12] {L-Lys};
\draw (h12) -- (e11);
\node (c1) [CIR,suppress join,
right=of e13] {Gly};
\draw (e13) -- (c1);
%
\node (c1) [CIR] {Gly};
\node (c2) [CIR] {Gly};
\node (c3) [CIR] {Gly};
\node (c4) [CIR] {Gly};
\node (e21) [ELL=teal,on chain,join=by -] {D-Ala};
\node (e22) [ELL=purple,below left=of e21] {L-Lys};
\node (e23) [ELL=purple!50!black,
below left=of e22,
pin=left:\ce{NH2}] {D-Glu};
\node (e24) [ELL=teal,below left=of e23] {L-Ala};
%
\node (h23) [HEX=DarkMagenta,
below=of e24] {MurNAc};
\node (h22) [HEX=RoyalBlue,left=of h23] {GlcNAc};
\node (h21) [HEX=DarkMagenta,left=of h22] {MurNAc};
\node (h24) [HEX=RoyalBlue,suppress join,
right=of h23] {GlcNAc};
\draw (h21.west) -- + (-0.5,0)
(h23) -- (h24)
(h24.east) -- + ( 0.5,0);
%
\node (A) [CIR,ball color=yellow, suppress join,
left=of e11] {A};
\node (e25) [ELL=teal,suppress join,
below=of e13] {L-Ala};
\draw (e13) -- (e25);
\node (t1) [TRI, above=of c3] {E4};
\coordinate (t2) at ($(c4)!0.5!(e21)$);
\node (t3) [TRI, at=(t2 |- t1)] {E5};
\draw[-latex,red, shorten <=1mm, shorten >=1mm]
(A) edge ($(h12)!0.5!(e11)$)
%
(t1) edge ($(c2)!0.5!(c3)$)
(t1) edge ($(c3)!0.5!(c4)$)
(t3) to (t2);
\end{tikzpicture}
\end{document}