Graphics, Figures & TablesHow to create a new node type

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
usr345
Posts: 37
Joined: Fri Apr 01, 2011 11:39 pm

How to create a new node type

Post by usr345 »

I am trying to create an algorithm scheme. And have a special node for comment.
How can I create a new shape for the comment, using \pgfdeclareshape?
Tikz manual description of creating a new node on page 625 is too hard for me.

So I could write:

Code: Select all

\node [comment, below of=node-1] (node-2) {comment comment comment};
\path [line] (node-1) -- (node-2);
\node[terminator, below of=node-2, node distance=1.5cm] (node-3) {end};
\path [line] (node-2) -- (node-3);
The wanted node shape.
The wanted node shape.
tikZ-node-type.png (5.13 KiB) Viewed 2045 times

Code: Select all

\documentclass{article}
\usepackage[a4paper,landscape]{geometry}
\usepackage[cm]{fullpage}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,backgrounds,calc}
\begin{document}

\begin{tikzpicture}[node distance = 1.7cm, auto]
\tikzset{
	line/.style = {draw},
	comment/.style = {rectangle, draw, text centered, rounded corners, minimum height=2em,fill=white},
	terminator/.style = {shape=rounded rectangle, draw, inner sep=2mm},
}

\node[terminator] (node-1) {begin};

\node [comment, below of=node-1] (node-2) {comment comment comment};

\begin{scope}[on background layer]
	\draw[fill=gray!10] ($(node-2.south west)+(-2mm,-2mm)$) rectangle ($(node-2.north east)+(2mm, 2mm)$);
\end{scope}

\path [line] (node-1) -- ($(node-2.north)+(0mm,+2mm)$);

\node[terminator, below of=node-2, node distance=1.5cm] (node-3) {end};

\path [line] ($(node-2.south)+(0mm,-2mm)$) -- (node-3);

\end{tikzpicture}

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Post Reply