I want to add the following figure in the presentation of a paper I read. I read a small introduction to tikz but still the figure is very complicated for me to do. Can anybody help or point any guides to help me?
[Tex/LaTex] Tikz drawing a ring with nodes
diagramstikz-pgf
Related Solutions
You can also draw that path at one go so you don't need to fill white to restrict the fill if you have something else underneath it. And while you are at it you can also place the labels and coordinates too.
\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
\filldraw[fill=blue] (0,0)
coordinate[label=-90:$B$] (B)
arc (180:0:3cm)
coordinate[label=-90:$A$] (A)
arc (0:180:2cm)
coordinate[label=-90:$P$] (P)
arc (0:180:1cm);
\draw (B)--(A) coordinate[midway,label=-90:$O$] (O);
\draw[decoration={brace,raise=5mm},decorate] (A) -- (O)
node [midway,yshift=-6mm,below] (R) {$6$};
\draw[decoration={brace,raise=5mm},decorate] (O) -- (P)
node [midway,yshift=-6mm,below] (r) {$x$};
\end{tikzpicture}
\end{document}
a proposal for the first two diagrams the third should be easily
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc,decorations}
\usetikzlibrary{positioning}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\node[draw, minimum width=12em,minimum height=1em, inner sep=0] (S1) at (0,0){};
\path (S1.south west) -- (S1.south east) coordinate[pos=0.1](p1) coordinate[pos=0.9](p2)coordinate[pos=0.5](c1);
\node[draw, minimum width=1em,minimum height=8em, inner sep=0,below=0em of p1 ] (S2){};
\node[draw, minimum width=1em,minimum height=8em, inner sep=0,below=0em of p2 ] (S3){};
\node[draw, minimum width=1em,minimum height=12em, inner sep=0,below=0em of c1 ] (S4){};
\node[draw, minimum width=1em,minimum height=12em, inner sep=0,below=0em of c1, rotate around={10:(c1)},dashed] (S4){};
\end{tikzpicture}
\begin{tikzpicture}
\node[draw, minimum width=12em,minimum height=1em, inner sep=0] (S1) at (0,0){};
\path (S1.south west) -- (S1.south east) coordinate[pos=0.1](p1) coordinate[pos=0.9](p2)coordinate[pos=0.5](c1);
\node[draw, minimum width=1em,minimum height=8em, inner sep=0,below=0em of p1 ] (S2){};
\node[draw, minimum width=1em,minimum height=8em, inner sep=0,below=0em of p2 ] (S3){};
\node[ minimum width=1em,minimum height=8em, inner sep=0,below=0em of c1 ] (S4){};
\node[ minimum width=1em,minimum height=8em, inner sep=0,below=0em of c1, rotate around={15:(c1)}] (S4b){};
\draw[decoration={zigzag,amplitude=1em},decorate] (S4.north) -- (S4.south);
\draw[decoration={zigzag,amplitude=1em},decorate] (S4b.north) -- (S4b.south);
\node[ minimum width=1em,minimum height=8em, inner sep=0,below=0em of S4.south,draw ] (S5){};
\node[ minimum width=1em,minimum height=8em, inner sep=0,below=0em of S4b.south, draw ] (S5){};
\end{tikzpicture}
\end{document}
Best Answer
Ok, let’s work it through.
I used the
through
library because we can simply use the anchors of the node as a reference and don’t have to worry where the circle exactly is in our picture.Styles
I defined three styles:
dot node
style is for the simple nodes on the circle, I have usedfill=white
so that the circle is not seen in the circle. This works best with a simple background.dotdot node
inherits thedot node
style but also places a filled dot inside it (disguised as a label).arc style
is for the arc arrows in the circle, the shorten amount is needed so that the|
part of the arrow overlap for connecting arrows. For more discussion and other solutions on that matter, see TikZ arrow tip is displacedThe
dotdot node
style expects two mandatory arguments. The one is used to name the node, the second is used for any options for the label. We use this later to place a pin at the label (the black dot in the node).TikZ picture options
The options to the
tikzpicture
are:thick
,every ping edge/.style={<-}
which sets the arrow style for the pins. If you use other pins in your code, you will need to change this and declare a separate style that is used for the pin edge.>=latex
sets the default arrow for the>
arrow tip. I don’t like theto
style much so I setlatex
here.The following
declare function
is used to declare some constants (the outer radius and the inner radius for the circle and the arrow arcs) and a functionangleofNode
that takes on argument, the number of the node. As we place 23 nodes, this function easily calculates the angle on a circle.We could have used also LaTeX macros, i.e.
and could have used these macro instead of the PGF math functions.
Drawing
The outer circle is easy. The
circle through
key from thethrough
library is used to easily draw the circle. We name the nodec
for the next steps.The points on the circle are now accessible by
c.east
,c.30
,c.170
, etc. We use this to place our simpledot node
s there. The\foreach
loop can be used to draw a bunch of nodes.Another
\foreach
loop is used to draw thedotdot node
s. In this same step we also draw the labelsA_{<something>}
, name thedotdot node
sdd-<number>
and also the black dots inside thedotdot node
s. These are namedddd-<number>
, this is done by the first argument to thedotdot node
style. The second argument is used to for thepin
with the textT_{<something>}
.In bot cases
<something>
is the macro\tLabel
which we have declared for every step in the loop with the second value. The directions for the label and the pins are also defined in the loop. The\foreach
loop from TikZ is very powerful and has its own tag foreach. A short introduction can be found in Structure, Tuple or Dict for the foreach-loop in Tikz.The third and final
\foreach
loop is used to draw the arcs. Now, this is not that easy as we don’t have a circle to reference. Even if we had, we would have to draw the arc ourself.The
arc
path operator does not draw an arc from one point to another with a specified radius. It draws an arc from the last point on the path with a radius, a certain start and a certain end angle. (There is alsodelta angle
for when you only have one of the other angles.)So, we need to move to one of the points on the arc:
({angleofNode(\sAngle)}:innerR)
. Then we draw anarc
with the radius ofinnerR
from the node\sAngle
to\eAngle
. Again, theangleofNode(<node number>)
function helps us to find the correct angle. Unfortunately, the placement of nodes along ofarc
s is non-function (in the current release version of TikZ anyway), so I also place the node manually halfway along the path but.3cm
to the center. This has been discussed before in How to place a node in the middle of an arc?.Code
Output