在 LaTeX 中制作此图

在 LaTeX 中制作此图

我正在尝试用 TeX 生成下图:在此处输入图片描述

带有彩色方块。到目前为止,我所做的是:

\documentclass{article}
\usepackage{xcolor}
\begin{document}
\centering
\fboxsep=10mm \fboxrule=0.5mm
\fcolorbox{black}{blue!40!white}{{\bf P}}\\[2cm]

\fboxsep=3mm \fboxrule=0.5mm
\fcolorbox{black}{blue!40!white}{$a_1$}\fcolorbox{black}{blue!40!white}{$o_1$}\fcolorbox{black}{blue!40!white}{$a_2$}\fcolorbox{black}{blue!40!white}{$o_2$}\fcolorbox{black}{blue!40!white}{$a_3$}\fcolorbox{black}{blue!40!white}{$o_4$}\\[2cm]

\fboxsep=10mm \fboxrule=0.5mm
\fcolorbox{black}{blue!40!white}{{\bf Q}}

\end{document}

但看起来我无法继续使用这种方法,因为对于箭头,我需要 tikz(对吧?!)。另一方面,我对图形右侧的符号以及如何生成它一无所知!此外,我的正方形和原始图形之间存在令人讨厌的距离,字符所在的带状矩形的外边界比内线更宽。我该如何生成它?

答案1

一种可能的TiKZ解决方案。它使用\matrix中央磁带以及0pt宽度规则,用于在节点内底部对齐文本(P 和 Q)。箭头穿透具有负shorten参数的形状。最后在矩阵边界上绘制一条较粗的线。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows,matrix,positioning}

\begin{document}
\begin{tikzpicture}[>=stealth']

\matrix (tape) [matrix of math nodes, inner sep=0pt, nodes={draw, inner sep=3pt, fill=blue!40, outer sep=0pt}, column sep=-\pgflinewidth, inner sep=0pt] {a_1 & o_1 & a_2 & o_2 & a_3 & o_3 & a_4 & o_4 & a_5 & o_5 \\};

\node[draw, minimum width=12mm, above = 6mm of tape-1-5.north east, fill=blue!40] (P) {\rule{0cm}{1cm}P};

\node[draw, minimum width=12mm, below = 6mm of tape-1-5.south east, fill=blue!40] (Q) {\rule{0cm}{1cm}Q};

\draw[<-, shorten <=-2pt] (tape-1-5.north)--(tape-1-5|-P.south);
\draw[->, shorten >=-2pt] (tape-1-5.south)--(tape-1-5|-Q.north);
\draw[->, shorten >=-2pt] (tape-1-6.north)--(tape-1-6|-P.south);
\draw[<-, shorten <=-2pt] (tape-1-6.south)--(tape-1-6|-Q.north);

\draw[shorten <=-1mm, shorten >=-1mm] ([xshift=2mm]tape-1-10.north east) to [bend left] ([xshift=2mm]tape-1-10.east) to [bend right] ([xshift=2mm]tape-1-10.south east);
\draw[shorten <=-1mm, shorten >=-1mm] ([xshift=3mm]tape-1-10.north east) to [bend left] ([xshift=3mm]tape-1-10.east) to [bend right] ([xshift=3mm]tape-1-10.south east);
\draw[fill=blue!40] (tape-1-10.north east)--([xshift=2mm]tape-1-10.north east) to [bend left] ([xshift=2mm]tape-1-10.east) to [bend right] ([xshift=2mm]tape-1-10.south east)--(tape-1-10.south east)--cycle;

\draw[thick] ([xshift=2mm]tape-1-10.north east)-|(tape-1-1.west)|-([xshift=2mm]tape-1-10.south east);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

不使用tikz示意图也可以走得很远。但是,简单的代价是妥协。例如,在这个 MWE 中,我使用了省略号...而不是轴断点符号。此外,由于我缩放了文本大小的箭头,因此头部可能比你喜欢的要大。

我的基本方法是堆叠已经创建的元素,以挤出垂直空间。此外,我引入了在放置 后\ffcolorbox仅将距离左对齐的元素,以避免框之间出现双倍粗线。我还在框的左侧放置了一个幻影省略号,以便将框的中央行对称放置。\fboxrule\fcolorbox

\documentclass{article}
\usepackage{xcolor}
\newcommand\ffcolorbox[3]{\fcolorbox{#1}{#2}{#3}\kern-\fboxrule}
\usepackage[usestackEOL]{stackengine}
\setstackgap{S}{0pt}
\usepackage{graphicx}
\begin{document}
\centering
\fboxsep=10mm\fboxrule=0.5mm
\Shortstack{%
\fcolorbox{black}{blue!40!white}{{\bf P}}\\\scalebox{4}{$\downarrow\uparrow$}\\
\fboxsep=3mm \fboxrule=0.5mm\phantom{\scalebox{2.5}{\ldots}}
\ffcolorbox{black}{blue!40!white}{$a_1$}\ffcolorbox{black}{blue!40!white}%
{$o_1$}\ffcolorbox{black}{blue!40!white}{$a_2$}\ffcolorbox{black}{blue!40!white}%
{$o_2$}\ffcolorbox{black}{blue!40!white}{$a_3$}\fcolorbox{black}{blue!40!white}%
{$o_4$}\scalebox{2.5}{\ldots}\\
\scalebox{4}{$\downarrow\uparrow$}\\\fboxsep=10mm\fboxrule=0.5mm%
\fcolorbox{black}{blue!40!white}{{\bf Q}}%
}
\end{document}

在此处输入图片描述

回应评论,也可以通过使用负堆叠间隙来提供所需的重叠。但是,必须确保箭头最后堆叠,以便它们最终位于顶部。此要求使语法有些复杂,但仍然是可能的。每个\stackon\stackunder都有其可选参数堆叠间隙。重叠用中央胶带显示。如果希望与和PQ重叠,则应将[0pt][-1pt]间隙设置设置得更负。

\documentclass{article}
\usepackage{xcolor}
\newcommand\ffcolorbox[3]{\fcolorbox{#1}{#2}{#3}\kern-\fboxrule}
\usepackage[usestackEOL]{stackengine}
\usepackage{graphicx}
\begin{document}
\centering
\fboxsep=10mm\fboxrule=0.5mm
\stackunder[-5pt]{\stackon[-5pt]{%
\fboxsep=3mm \fboxrule=0.5mm\phantom{~~~~~~~~.}
\ffcolorbox{black}{blue!40!white}{$a_1$}\ffcolorbox{black}{blue!40!white}%
{$o_1$}\ffcolorbox{black}{blue!40!white}{$a_2$}\ffcolorbox{black}{blue!40!white}%
{$o_2$}\ffcolorbox{black}{blue!40!white}{$a_3$}\fcolorbox{black}{blue!40!white}%
{$o_4$}\scalebox{2.5}{\ldots}%
}
{\stackunder[0pt]{\fcolorbox{black}{blue!40!white}{{\bf P}}}
  {\scalebox{4}{$\downarrow\uparrow$}}}
}{%
\stackon[-1pt]{\fcolorbox{black}{blue!40!white}{{\bf Q}}}%
  {\scalebox{4}{$\downarrow\uparrow$}}
}
\end{document}

在此处输入图片描述

答案3

纯粹为了娱乐价值元帖子(我正在等待磁盘恢复完成......)

在此处输入图片描述

prologues:=3;outputtemplate:="%j%c.eps";
beginfig(1);

path segment[];
for i=1 upto 11:
  segment[i] = unitsquare xscaled 21 yscaled 13 shifted (21i,0);
  fill segment[i] withcolor .8[blue,white];
  draw segment[i];
  draw subpath(0,1) of segment[i] withpen pencircle scaled 1;
  draw subpath(2,3) of segment[i] withpen pencircle scaled 1;
endfor

for i=1 upto 5:
  write "label(btex $a_" & decimal i & "$ etex, center segment[" & decimal (2i-1) & "]);" to ".mplabels";
  write "label(btex $o_" & decimal i & "$ etex, center segment[" & decimal (2i) & "]);" to ".mplabels";
  endfor
write EOF to ".mplabels";
input .mplabels;

w = 25;
path wiggle; 
wiggle = (10 down { up rotated w } .. origin {up rotated -w} .. 10 up { up rotated w})
         shifted center segment[11] shifted 3 left;

clip currentpicture to ( (up--down) scaled 12 shifted (0,ypart center segment[11]) -- wiggle -- cycle);

draw wiggle;
draw wiggle shifted 3 right;

path P, Q;
s = 3;

P = unitsquare shifted -(1/2,1/2) scaled 42 shifted urcorner segment[2s-1] shifted 42 up;
fill P withcolor .7[red,white]; draw P;
label.top(btex P etex scaled 1.2, point 1/2 of P);

Q = unitsquare shifted -(1/2,1/2) scaled 42 shifted lrcorner segment[2s-1] shifted 42 down;
fill Q withcolor .7[green,white]; draw Q;
label.top(btex Q etex scaled 1.2, point 1/2 of Q);

z1 = point 5/2 of segment[2s-1];
z2 = point 5/2 of segment[2s];
z3 = point 1/2 of segment[2s-1];
z4 = point 1/2 of segment[2s];

drawarrow (x1,ypart point 0 of P) -- z1 shifted 2 down;
drawarrow z2 -- (x2,ypart point 0 of P) shifted 2 up;
drawarrow z3 -- (x3,ypart point 3 of Q) shifted 2 down;
drawarrow (x4,ypart point 3 of Q) -- z4 shifted 2 up;

endfig;
end

相关内容