13

How can I make straight line between two nodes when one node, for example, above another one and shorter.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}
\usepackage{amsmath,bm,times}
\usepackage{verbatim}

\begin{document}
\pagestyle{empty}

% We need layers to draw the block diagram
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

% Define a few styles and constants
\tikzstyle{sensor}=[draw, fill=blue!20, text width=5em, 
    text centered, minimum height=2.5em]
\tikzstyle{sensor}=[draw, fill=blue!20, text width=5em, 
    text centered, minimum height=2.5em]
\tikzstyle{ann} = [above, text width=5em]
\tikzstyle{naveqs} = [sensor, text width=6em, fill=red!20, 
    minimum height=12em, rounded corners]
\tikzstyle{mainblock} = [above,sensor, text width=6em, fill=yellow!20,
    minimum height=12em, rounded corners, dashed]

\tikzstyle{main} = [rounded corners, fill=yellow!20,
    minimum width=7cm,minimum height=5cm, text centered]

\tikzstyle{submain} = [node distance=0.4cm, rounded corners, fill=red!20,
    minimum width=6.5cm,minimum height=0.7cm, text centered, draw, rectangle]

\tikzstyle{subsubmain} = [node distance=0.2cm, rounded corners,   fill=green!20,
    minimum width=6cm,minimum height=0.7cm, text centered, draw, rectangle]
\tikzstyle{header} = [submain, fill=blue!10]
\def\blockdist{2.3}
\def\edgedist{2.5}

\begin{tikzpicture}[scale=3.0]
\node (mobprint)[main,draw,rectangle] {};
\path (mobprint.north) node (exper) [header] {MobilePrint Application};
\node (gui) [submain,below=of exper] {GUI Interface};
\node (pssub) [submain, below=of gui, minimum height=3cm] {Subsystem};
\node (opmap) [subsubmain, above=0.1cm of pssub.south,
minimum width] {Option Mapping};
\node (storage) [subsubmain, above left=0.4cm and 0cm of opmap.north east, minimum width=3cm] {Compressed Storage};
\path [draw, ->] (storage) -- (opmap);
\draw (storage) edge (opmap);
\end{tikzpicture}
\end{document}

enter image description here

P.S.: I wish to connect (storage) "Compressed Storage" to (opmap) "Option Mapping"

  • 2
    Welcome to TeX.sx! Do you intend to put storage to the upper right part of mapping and pssub to the upper left part of mapping? – hpesoj626 Mar 19 '13 at 7:10
  • 1
    Could you please clarify which nodes you wish to connect. – Andrew Swann Mar 19 '13 at 7:12
  • 1
    Sorry, updated original question. – likern Mar 19 '13 at 7:38
  • 3
    Try \draw [->] (storage) -- (storage |- opmap.north); – hpesoj626 Mar 19 '13 at 8:02
16

Here is an attempt, although I have to admit I don't fully understand what you are trying to achieve here. Do you want to draw a vertical line from storage node to opmap? Then the coordinate system perpendicular is your friend. See page 130 of the pgfmanual. Here, we used the implicit syntax (<p>|- <q>). I also repositioned the Subsystem label as it is being covered by the storage node.

Finally, the code.

%\documentclass{article}
\documentclass[tikz,border=5,convert]{standalone}

%\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}
\usepackage{amsmath,bm,times}
\usepackage{verbatim}

\begin{document}
%\pagestyle{empty}

% We need layers to draw the block diagram
%\pgfdeclarelayer{background}
%\pgfdeclarelayer{foreground}
%\pgfsetlayers{background,main,foreground}

% Define a few styles and constants
\tikzstyle{sensor}=[draw, fill=blue!20, text width=5em, 
    text centered, minimum height=2.5em]
\tikzstyle{sensor}=[draw, fill=blue!20, text width=5em, 
    text centered, minimum height=2.5em]
\tikzstyle{ann} = [above, text width=5em]
\tikzstyle{naveqs} = [sensor, text width=6em, fill=red!20, 
    minimum height=12em, rounded corners]
\tikzstyle{mainblock} = [above,sensor, text width=6em, fill=yellow!20,
    minimum height=12em, rounded corners, dashed]

\tikzstyle{main} = [rounded corners, fill=yellow!20,
    minimum width=7cm,minimum height=5cm, text centered]

\tikzstyle{submain} = [node distance=0.4cm, rounded corners, fill=red!20,
    minimum width=6.5cm,minimum height=0.7cm, text centered, draw, rectangle]

\tikzstyle{subsubmain} = [node distance=0.2cm, rounded corners,   fill=green!20,
    minimum width=6cm,minimum height=0.7cm, text centered, draw, rectangle]
\tikzstyle{header} = [submain, fill=blue!10]
%\def\blockdist{2.3}
%\def\edgedist{2.5}

\begin{tikzpicture}[scale=3.0]
\node (mobprint)[main,draw,rectangle] {};
\path (mobprint.north) node (exper) [header] {MobilePrint Application};
\node (gui) [submain,below=of exper] {GUI Interface};
\node (pssub) [submain, below=of gui, minimum height=3cm] {};
\node (opmap) [subsubmain, above=0.1cm of pssub.south,
minimum width] {Option Mapping};
\node (storage) [subsubmain, above left=0.4cm and 0cm of opmap.north east, minimum width=3cm] {Compressed Storage};

% Draw a line from storage perpendicular to opmap
\draw [->] (storage) -- (storage |- opmap.north); 
% Position the label at the top portion of pssub node
\node at (pssub.north) [anchor=north] {Subsystem};
\end{tikzpicture}
\end{document}

enter image description here

By the way, consider replacing your \tikzstyle's with \tikzset. I have also commented some lines of code that were not used. You can uncomment them later in your actual use case. Also, consider using newtxtext and newtxmath in place of times package.

  • 1
    Thanks, that's exactly what I wanted - draw vertical line from one node to another. – likern Mar 19 '13 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.