6

I am trying to generate the following figure in TeX:enter image description here

With coloured squares. What I have done so far is:

\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}

But it looks like I cannot continue any further with this approach because for arrows I will need tikz(right?!). On the other hand I don't have a clue about the sign on the right of the figure and how to generate that! Plus there is this annoying distance between my squqares and in the original figure the outer boundary of the tape-like rectangle that the characters are in is wider than the inner lines. How can I generate that?

Naji
  • 1,505
  • 1
    You might take a look at Ipe, if you're willing to use a drawing editor rather than writing code. I expect you could sketch something like that in about 5 minutes. – G. Poore Jan 13 '14 at 20:01
  • @G.Poore thanks for letting me know that such a thing exist. Although I'd rather have it as part of my code and that is why I am looking for either tikz version or normal version in tex. – Naji Jan 13 '14 at 23:15
  • 2
    Could you choose a better title for your post? For example, what does the image represent? That way future users who visit our search the site might be able to find it rather than a search for "this figure". – Werner Dec 24 '15 at 17:54

3 Answers3

5

One can go quite far without the use of tikz for schematics. However, the cost of simplicity is compromise. For example, in this MWE, I used an ellipsis ... instead of an axis-break symbol. Also, because I scaled the text-size arrows, the heads may be bigger than you like.

My basic approach was to stack the elements that you had already created, in order to squeeze out the vertical space. Also, I introduced \ffcolorbox which just kerned left the distance \fboxrule following the placement of an \fcolorbox, in order to avoid having double-thick lines between the boxes. I also placed a phantom ellipsis to the left of the boxes, so that the central row of boxes would be symmetrically placed.

\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}

enter image description here

In response to the comment, it is also possible to provide the desired overlaps, by using negative stack gaps. However, it must be assured that the arrows are stacked last, so that they end up on top. This requirement complicates the syntax somewhat, but is still possible. Each \stackon and \stackunder has as its optional argument the stacking gap. Overlap is shown with the central tape. If overlap is desired with the P and Q boxes, the [0pt] and [-1pt] gap settings should be set more negatively.

\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}

enter image description here

  • Thanks a lot but I actually wouldn't mind to get a help for tikz version cause I want the arrows to penetrate the tape + the wave like symbol on the right... how to create that? – Naji Jan 13 '14 at 23:14
  • 1
    @Naji The overlap is possible (see revision). However, the wave-like symbol is elusive with my approach. – Steven B. Segletes Jan 14 '14 at 02:05
  • 1
    I really appreciate your ingenuity to extend it as much as possible without tikz! :) – Naji Jan 14 '14 at 10:32
4

A possible TiKZ solution. It uses a \matrix for central tape and 0pt width rules to bottom align text (P and Q) inside nodes. Arrows penetrate shapes with negative shorten parameters. Finally a thicker line is drawn over matrix border.

\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}

enter image description here

Ignasi
  • 136,588
4

Purely for amusement value in Metapost (while I'm waiting for a disk recovery to complete...)

enter image description here

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
Thruston
  • 42,268