I am interested to make some diagrams like the sample picture. I am not sure whether it can be done using Latex or not. Can anybody give any idea. Thanks.
-
It certainly can if you don't mind the time and the learning curve. Take a look at TikZ and PS Tricks. Also, there's a nice comparison of the two here http://tex.stackexchange.com/questions/6676/what-are-the-advantages-of-tikz-pgf-over-pstricks – Au101 Feb 10 '16 at 23:22
2 Answers
For starting point in your learning (in case that as basic tool you select TikZ package) can serve the following MWE:
\documentclass[tikz, border=3mm]{standalone}
\usetikzlibrary{chains,decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[
node distance=0pt,
start chain = A going right,
X/.style = {rectangle, draw,% styles of nodes in string (chain)
minimum width=2ex, minimum height=3ex,
outer sep=0pt, on chain},
B/.style = {decorate,
decoration={brace, amplitude=5pt,
pre=moveto,pre length=1pt,post=moveto,post length=1pt,
raise=1mm,
#1}, % for mirroring of brace, if necessary
thick},
B/.default=mirror, % by default braces are mirrored
]
\foreach \i in {0,1,1,0,0,0,1,0,0,
0,1,0,1,0,0,0,1,0,
0,0,1,1,0,0,1,0,0}% <-- content of nodes
\node[X] {\i};
\draw[B] ( A-1.south west) -- node[below=2mm] {Channel 1 Links} ( A-9.south east);
\draw[B] (A-10.south west) -- node[below=2mm] {Channel 2 Links} (A-18.south east);
\draw[B] (A-19.south west) -- node[below=2mm] {Channel 3 Links} (A-27.south east);
\node (B1) [inner sep=1pt,above=of A-10.north west] {$\times$};
\node (B2) [inner sep=1pt,above=of A-19.north west] {$\times$};
\draw[B=](B1.north) -- node[above=2mm] {Crossover Points}(B2.north);
\end{tikzpicture}
\end{document}
which gives:
Short explanation of code: Above code is (very) concise, so for it understanding some experience with TikZ package is necessary. In it design I considered the following:
The simple structure of picture. It has 27 nodes with equal shapes which form a chain. Therefore the
chainslibrary from TikZ is used for their positioning. It is defined by optionstart chain = A going right, where A is chain name. Consequently nodes in chain are named A-1, A-2, ... , A-27.Distances between nodes in chain is determined by
node distance. Its default value is 15 mm, so withnode distance=0ptit is set to zero, so nodes are separated only byouter sepparameter of shapes. That border lines are properly overlapped, also this distance is set to zero (in definition of nodes' style, it is named X)In the TikZ the
foreachloops is intended to do repeating task. Such task is setting nodes in chain. with\forach \i in {...}\node[X] {\i};are formed a chain of nodes (with style X), with content determined by list in curly braces. Since their positions are determined by chain, the loop actually only determine their number and content.
Braces below and above nodes is drawn by use of
decorations.pathreplacinglibrary. In it definition among their parameters the parametermirroris select as free parameter which is can be determined later. Since the three from four braces are mirrored, this is set as default and exception is determined "locally".Braces is designed so, that they are
1ptshorter on each side than is distance between coordinates, and withraise=1mmis move below (when is mirrored) or above (when is not mirrored) from given coordinates.The crosses above begin and end of "channel 2 links" is set on "classic way" with
above=of <coordinate name>and for it is used math symbol for multiplying.
More deep description of principle of TikZ which are used heree is in TikZ manual:
- for chains: chapter 46 Chains, page 541
- for
\foreachloop: chapter 83 Repeating Things: The Foreach Statement, page 901 - for braces: subsection 48.3 Path Replacing Decorations, page 581
- 296,517
-
would you be willing to annotate that code a bit? For example, is the code from
node distancethrough the\foreachloop all one command? – dedded Feb 11 '16 at 02:38 -
A short code with pstricks:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{mathtools}
\usepackage{pstricks-add, multido}
\usepackage{auto-pst-pdf}
\begin{document}
\sffamily
\begin{pspicture}
\psset{dimen=middle, linewidth=0.6pt, braceWidthOuter=4pt, braceWidthInner=4pt, braceWidth=0.8pt, labelsep =-2ex}
\multido{\i = 0 + 1, \n=0+0.5}{27}{\fnode[framesize=0.5](\n, 0){A\i}}%
\rmultiput{$0$}(A0)(A3)(A4)(A5)(A7)(A8)(A9)(A11)(A13)(A14)(A15)(A17)(A18)(A19)(A22)(A23)(A25)(A26)
\rmultiput{$1$}(A1)(A2)(A6)(A10)(A12)(A16)(A20)(A21)(A24)
\psset{rot=90, nodesepB=2ex}
\multido{\ia=0 + 9, \ib=8 + 9}{3}{\pnode[-0.15, -0.35](A\ia){B\ia}\pnode[0.15, -0.35](A\ib){B\ib}\psbrace(B\ia)(B\ib){\clap{Channel\,1 Links}}}
\multido{\i=8 + 9}{2}{\pnode[0.25,0.6](A\i){C\i}\uput{1pt}[d](C\i){$\times$}}
\psbrace[rot=-90, nodesepB=-0.5ex](C17)(C8){\clap{Crossover Points}}
\end{pspicture}
\end{document}
- 271,350


