trying to connect two boxes in flowchart latex - latex

I am using overleaf and trying to connect like following.
see image here
The code is shared using overleaf
https://www.overleaf.com/3275194655nwtxkzncnhqt

Quick and dirty hack for the arrow: \draw[arrow] ([xshift=-0.5cm]Modify AC coefficients.south) -| ([xshift=3cm]Watermarked Image.north);
Please
note that you should not use \tikzstyle, this is obsolete.
also check that latin1 is really the appropriate encoding for your document. The vast majority of editors use utf8 by default.
don't misuse x for \times
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>
\begin{document}
\pagestyle{empty}
\tikzset
{
arrow/.style={
->,>=stealth}
}
% Define block styles
\tikzstyle{decision} = [diamond, draw,
text width=4.5em, text badly centered, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw,
text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{block1} = [rectangle, draw,
text width=6em, text centered, rounded corners, minimum height=4em]
\tikzstyle{block2} = [rectangle, draw,
text width=15em, text centered, rounded corners, minimum height=4em]
\tikzstyle{block3} = [rectangle, draw,
text width=20em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\begin{tikzpicture}[node distance = 2.5cm, auto]
% Place nodes
\node [block3] (Watermarked Image) {Watermarked Image};
\node[decision, above of =Watermarked Image,node distance=4cm ] (Difference between selected coefficients) {Difference between selected coefficients };
\node [block, left of=Difference between selected coefficients, node distance=3.5cm] (Inverse DCT for each block)
{Inverse DCT for each block};
\node [block, right of=Difference between selected coefficients, node distance=3.5cm] (Modify AC coefficients)
{Modify AC coefficients and perform Inverse DCT for each block};
\node [block2, above of=Difference between selected coefficients] (Genetic Algorithm)
{Genetic Algorithm search DCT coefficients to find best option for insert watermark};
\node [block, above of=Genetic Algorithm] (DCT for each block)
{DCT for each block};
\node [block, left of=DCT for each block] (Watermark Message)
{Watermark Message};
\node [block, above of=DCT for each block] (8x8 Image Blocking)
{8x8 Image Blocking};
\node [block, above of=Watermark Message] (Host Image)
{Host Image};
% Draw edges
\path [line] (Host Image) -- (8x8 Image Blocking);
\path [line] (8x8 Image Blocking) -- (DCT for each block);
\path [line] (DCT for each block) -- (Genetic Algorithm);
%\path [line] (Watermark Message) -- (Genetic Algorithm);
%\path [line] (Modify AC coefficients) -- (Inverse DCT for each block);
%\path [line] (Inverse DCT for each block) -- (Watermarked Image);
\path [line] (Genetic Algorithm) -- (Difference between selected coefficients);
\path [line] (Difference between selected coefficients) -- node {yes} (Inverse DCT for each block);
\path [line] (Difference between selected coefficients) -- node {no}(Modify AC coefficients);
\coordinate (n2nl) at ([xshift=-2cm]Genetic Algorithm.north);
\coordinate (n2nr) at ([xshift=-3cm]Watermarked Image.north);
\coordinate (n2ns) at ([xshift=3cm]Watermarked Image.east);
\draw[arrow] (Watermark Message.south -| n2nl) -- (n2nl);
\draw[arrow] (Inverse DCT for each block.south -| n2nr) -- (n2nr);
% \draw[arrow] (Modify AC coefficients.south -| n2ns) -- (n2ns);
\draw[arrow] ([xshift=-0.5cm]Modify AC coefficients.south) -| ([xshift=3cm]Watermarked Image.north);
\end{tikzpicture}
\end{document}

Related

Draw a grid with 32 cells, intermediate rectangles does not show up

I would like to draw a figure describing the floating-point IEEE754 specification.
Doing so, I tried to draw a grid with 32 rectangles. (I then figured out there is a grid command).
Here is a MWE for 4 cells:
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\newcommand{\width}{1}
\newcommand{\height}{2}
\foreach \x in {0, 1}{
\draw (\x, 0) rectangle (\x+\width, \height);
}
\foreach \x in {2, 3}{
\draw (\x, 0) rectangle (\x+\width, \height);
}
\end{tikzpicture}
\end{document}
I used two foreach. I could merge these into one, but I then obtain only the rectangles on the far left and far right side, not the four rectangles as in the first MWE. Why is it so ?
\begin{tikzpicture}
\newcommand{\width}{1}
\newcommand{\height}{2}
\foreach \x in {0, 4}{
\draw (\x, 0) rectangle (\x+\width, \height);
}
\end{tikzpicture}
By using \foreach \x in {0, 4} your list literally just has these two values, no intermediate values.
If you like to include intermediate steps, you can use \foreach \x in {0,...,3}
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\newcommand{\width}{1}
\newcommand{\height}{2}
\foreach \x in {0,...,3}{
\draw (\x, 0) rectangle (\x+\width, \height);
}
\end{tikzpicture}
\end{document}

How to draw following figure or similar using tikz and pgf

My thesis superviser asks to redraw this picture in order to cite it in my paper. Could someone help how? Maybe there is a software that can make drawn picture a latex code
enter image description here
Perhaps this will get you started. First make a suitable layout of the boxes by editing the foreach loop. After that, make the boxes one-by-one, e.g.
\draw (2,7) node[rectangle,fill=green!20]{$C$};
\draw (3,7) node[rectangle,fill=green!20]{$T_1$};
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.symbols}
\begin{document}
\begin{tikzpicture}[block/.style={signal, draw, signal to=north}]
\filldraw[fill=gray!20,rounded corners=5mm] (0,0) rectangle (10,10);
\filldraw[fill=blue!30!white,very thick] (1,4) rectangle (9,8);
\foreach \x in {2,3,4,5,6,7,8} {
\draw (\x,3) node[block,fill=yellow!50]{text};
\draw (\x,5) node[rectangle,fill=red!20]{text};
\draw (\x,7) node[rectangle,fill=green!20]{text};
\draw[->,line width=1mm] (\x,3.5) -- (\x,4.5);
}
\begin{scope}[shift={(13,0)}]
% #1, code needed also below
\filldraw[fill=gray!20,rounded corners=5mm] (0,0) rectangle (10,10);
\end{scope}
\begin{scope}[shift={(15,-0.2)}]
\filldraw[fill=gray!20,rounded corners=5mm] (0,0) rectangle (10,10);
\end{scope}
\begin{scope}[shift={(17,-0.4)}]
\filldraw[fill=gray!20,rounded corners=5mm] (0,0) rectangle (10,10);
\draw (0,0) circle (2pt);
\filldraw[fill=gray!20,rounded corners=5mm] (0,0) rectangle (10,10);
% copy paste contents from #1 and edit a little
\filldraw[fill=blue!30!white,very thick] (1,4) rectangle (9,8);
\foreach \x in {2,3,4,5,6,7,8} {
\draw (\x,3) node[block,fill=yellow!50]{text};
\draw (\x,5) node[rectangle,fill=red!20]{text};
\draw (\x,7) node[rectangle,fill=green!20]{text};
\draw[->,line width=1mm] (\x,3.5) -- (\x,4.5);
}
\end{scope}
\end{tikzpicture}
\end{document}

LaTex/TikZ - Box alignment

I created following LaTeX/TikZ script to draw a figure:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{arrows, chains}
\usetikzlibrary{positioning,shapes.multipart}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[draw, fill=yellow!96!black, rectangle,
align=center, inner sep=3ex, font=\sffamily, label=below: Label1] (Box1) {
\begin{tikzpicture}
\node[draw, shape=rectangle split, rectangle split parts=2,
inner sep=1ex, rounded corners=0pt,
fill=white, font=\vphantom{Q}\sffamily] (Innerbox) {One \nodepart{two} Two};
\end{tikzpicture}};
\node[draw, inner sep=1ex, right=of Box1, label=below: Label2] (Box2) {
\begin{tikzpicture}
\end{tikzpicture}
{\begin{tikzpicture}
\node[draw, fill=yellow!96!black, rectangle,
align=center, inner sep=3ex, font=\sffamily, label=below: Label3] (Box3) {Four};
\end{tikzpicture}}};
\draw (Box1) -- (Box2) -- (Box3);
\draw[dashed] (Innerbox.one east) -- (Box2);
\draw[dashed] (Innerbox.two east) -- (Box2);
\end{tikzpicture}
\end{document}
I want to solve following problems:
How can the boxes be aligned equal, so than the label below is always on the same level?
How can box "Four" be added (not within, but as a box like Box1) to the right of Box2, ideally with a dashed line from Box2 to Box3?
Desired structure:
[Box1] -- [Box2] -- [Box3]
My elementary approach to this picture:
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
% left box
\filldraw [fill=yellow, draw=black, ultra thick] (0,0) rectangle (8,-10);
\filldraw [fill=white, draw=black, ultra thick] (2,-2) rectangle (6,-5);
\filldraw [fill=white, draw=black, ultra thick] (2,-5) rectangle (6,-8);
\node at (4,-3.5) [font=\sffamily] {\Huge One};
\node at (4,-6.5) [font=\sffamily] {\Huge Two};
% right box
\filldraw [fill=white, draw=black, ultra thick] (12,0) rectangle (20,-10);
\filldraw [fill=yellow, draw=black, ultra thick] (13,-1) rectangle (19,-6);
\node at (16,-3.5) [font=\sffamily] {\Huge Four};
% labels
\node at (4,-11) {\Huge 1};
\node at (16,-11) {\Huge 2};
\node at (16,-7) {\Huge 3};
% lines
\draw [ultra thick] (8,-5) -- (12,-5);
\draw [loosely dashed, ultra thick] (6,-3.5) -- (12,-4);
\draw [loosely dashed, ultra thick] (6,-6.5) -- (12,-6);
\end{tikzpicture}
\end{document}
And its output:
Here you can play with coordinates to align boxes as you like.
This tries to answer to part 1 of your question while part 2 of it is not well clear to me. Anyway if you like this code, you can develop it and edit box Four just by using \filldraw, \draw and \node as above.

Latex tikz flowchart: how to move the label to blank spaces

I'm currently using Latex to make flowcharts and I found that the arrow goes through the label like this:
Surely with the codes:
%!TEX program = xelatex UTF8
\documentclass[UTF8]{ctexart}
\usepackage{tikz,mathpazo}
\usepackage{graphicx,amssymb,amstext,amsmath,newtxmath}
\usetikzlibrary{shapes.geometric, arrows}
\begin{document}
\thispagestyle{empty}
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [->,>=stealth]
\begin{tikzpicture}[node distance=2cm]
\node (start) [startstop] {Start};
\node (in1) [io, below of=start] {Input 1};
\node (pro1) [process, below of=in1] {Process 1};
\node (dec1) [decision, below of=pro1, yshift=-0.5cm] {Decision 1};
\node (out1) [io, left of=dec1,xshift=-2cm,yshift=-2cm] {Out 1};
\node (stop) [startstop, below of=out1] {Stop};
\node (dec2) [decision,right of=dec1,xshift=2cm,yshift=-2cm] {Decision 2};
\node (pro2) [process, right of=dec2, xshift=2cm] {Process 2};
\node (pro3) [process, below of=dec2, yshift=-0.5cm] {Process 3};
\draw [arrow](start) -- (in1);
\draw [arrow](in1) -- (pro1);
\draw [arrow](pro1) -- (dec1);
\draw [arrow](dec1) -| node[anchor=north] {Doch} (out1);
\draw [arrow](out1) -- (stop);
\draw [arrow](dec1) |- node[anchor=east] {Nein} (dec2);
\draw [arrow](dec2) -- node[anchor=east] {Nein} (pro3);
\draw [arrow](dec2) -- node[anchor=south] {Ja} (pro2);
\draw [arrow](pro2) |- (dec1);
\end{tikzpicture}
\end{document}
How can I move the label Doch to the blank space on the sides?
Use an additional left or above attribute:
\draw [arrow](dec1) -| node[anchor=north, left] {Doch} (out1); or
\draw [arrow](dec1) -| node[anchor=north, above] {Doch} (out1); should do the trick.

How to Find Intersections with Ellipses in PGF/TikZ

I am trying to display a sphere in PGF/TikZ to illustrate the idea of great circles.
The code for my current result is:
\begin{tikzpicture}
\tikzfading[name=fade right,
left color=transparent!20,
right color=transparent!90]
\tikzfading[name=fade out,
inner color=transparent!100,
outer color=transparent!10]
\tikzfading[name=fade right gc,
left color=transparent!0,
right color=transparent!70]
\draw [<->, dashed] (0,-5) -- (0,5); % y-axis
\draw [->, dashed] (0, 0) -- (20:5); % x-axis
\draw [->, dashed] (0, 0) -- (200:5); % x-axis
\draw [->, dashed] (0, 0) -- (340:5); % z-axis
\draw [->, dashed] (0, 0) -- (160:5); % z-axis
\fill [color=cyan, opacity=0.15, path fading=fade out] (0,0) circle (4cm); % bounding circle
\fill [color=cyan, opacity=0.25, path fading=fade right, fading angle=90] (0,0) ellipse (4cm and 1cm); % x-y-axis area
% great circle 1
\draw [rotate=-40, color=red, path fading=fade right gc, fading angle=40] (0,0) ellipse (4cm and 1cm);
% great circle 2
\draw[rotate=5, color=red, path fading=fade right gc, fading angle=5] (0,0) ellipse (1.5cm and 4cm);
\end{tikzpicture}
How do I
find the two points of intersection of the two red ellipses (commented as great circle 1 and 2),
find the point of intersection of a line (originating at the center (0,0)) with a ellipse, and
place a little circle or rectangle there?
Placing a little circle or rectangle there is not an issue.
Thank you very much!
Check out section 4.1.4. of the TikZ and PGF manual, titled "The Intersection of the Circles." You need to use the intersections library, which allows you to use the name intersections key, as in \path [name intersections={of=path 1 and path 2}] ;. To use this, you'll need to use the name path key, as in \draw [name path = y axis, <->, dashed] (0,-5) -- (0,5) ; % y-axis. Accessing the intersections seems to vary between versions; my local copy of the manual has different instructions from the one I linked you to. However, at least on my version, you then access the intersections with (intersection-1), (intersection-2), etc. To get circles at each intersection in your example, then, I would change your code to look like the following:
\begin{tikzpicture}
\tikzfading[ name = fade right
, left color = transparent!20
, right color = transparent!90 ]
\tikzfading[name = fade out
, inner color = transparent!100
, outer color = transparent!10 ]
\tikzfading[name = fade right gc
, left color = transparent!0
, right color = transparent!70]
\draw [name path = y axis, <->, dashed] (0,-5) -- (0,5) ; % y-axis
\draw [name path = x- axis, ->, dashed] (0, 0) -- (20:5) ; % x-axis
\draw [name path = x+ axis, ->, dashed] (0, 0) -- (200:5) ; % x-axis
\draw [name path = z+ axis, ->, dashed] (0, 0) -- (340:5) ; % z-axis
\draw [name path = z- axis, ->, dashed] (0, 0) -- (160:5) ; % z-axis
% bounding circle
\fill [color=cyan, opacity=0.15, path fading=fade out]
(0,0) circle (4cm) ;
% x-y-axis area
\fill [color=cyan, opacity=0.25, path fading=fade right, fading angle=90]
(0,0) ellipse (4cm and 1cm);
% great circle 1
\draw [ name path = great circle 1
, rotate = -40
, color = red
, path fading = fade right gc
, fading angle = 40]
(0,0) ellipse (4cm and 1cm);
% great circle 2
\draw [ name path = great circle 2
, rotate = 5
, color = red
, path fading = fade right gc
, fading angle = 5]
(0,0) ellipse (1.5cm and 4cm);
% Intersections
\path [name intersections={of=great circle 1 and great circle 2}] ;
\foreach \i in {1,...,4}
\fill [color=red] (intersection-\i) circle (2pt) ;
\path [name intersections={of=y axis and great circle 1}] ;
\fill (intersection-1) circle (2pt) ;
\fill (intersection-2) circle (2pt) ;
\path [name intersections={of=y axis and great circle 2}] ;
\fill (intersection-1) circle (2pt) ;
\fill (intersection-2) circle (2pt) ;
\foreach \a in {x,z} {
\foreach \ss in {+,-} {
\def\s.{\ss} % Otherwise the space in `\a\s axis` would get gobbled.
\path [name intersections={of=\a\s. axis and great circle 1}] ;
\fill (intersection-1) circle (2pt) ;
\path [name intersections={of=\a\s. axis and great circle 2}] ;
\fill (intersection-1) circle (2pt) ;
}
}
\end{tikzpicture}
Other than the reformatting (to avoid the horizontal scroll bar), all I have changed of your existing code is to add the name path key to your axes and great circles. I then added the intersections code, which should be relatively self-explanatory. Remember to \usetikzlibrary{intersections} first, and everything should work.

Resources