TeXblog

 Typography with TeX and LaTeX

Archive for the 'pgf/TikZ' Category

Drawing a stemma with TikZ

März 31st, 2012 by Stefan Kottwitz

Maïeul Rouquette has published an article on LaTeX-Community.org: Stemma with TikZ. It is an English translation of his three French blog articles about that topic.

A stemma codicum is a “family tree” of different manuscripts of a same text, see Stemmatics (Wikipedia). The article explains how to draw such a tree, which is also a method for constructing TikZ trees in general:

  • For simple trees, use nodes, edges and children with the TikZ tree syntax
  • For complex trees, you can go through these steps:
    1. Place the nodes, using coordinates or relatiive positioning, and give them names
    2. Apply styles for the nodes, choose or define your own styles for this
    3. Connect nodes by lines or arrows such as by \draw[->] (node1) — (node2);
Stemma with Tikz

Once you have created such a tree, you could easily use this as a template for further trees, if you don’t like to go through such a construction process each time. Though some things seem to be complicated with TikZ, it’s easy to re-use and to adjust for similar drawings. For this, the TikZ example gallery can give good start code. It also provides some examples for TikZ trees.

Category: pgf/TikZ, Graphics | No Comments »

LaTeX Workflow

Januar 18th, 2012 by Stefan Kottwitz

Agodemar posted a very nice diagram of the LaTeX workflow on TeX.SX:

LaTeX Workflow - compiler and application levels

A bigger version of the image and a link the full source code is shown in the topic Diagram / Infographic of TeX & friends.

Category: TeX.SX, pgf/TikZ, LaTeX General | No Comments »

Happy New Year!

Januar 1st, 2012 by Stefan Kottwitz

Happy New Year, and the best wishes!

Fireworks

The image shows fireworks displayed with TikZ by percusse on TeX.SX. Follow the link to see further fireworks effects.

The code is:

\documentclass{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{0pt}%
\usetikzlibrary{calc,decorations.pathmorphing}
%
\pgfdeclareradialshading{someshade}{\pgfpointorigin}{%
  color(0mm)=(pgftransparent!40);color(5mm)=(pgftransparent!50);%
  color(10mm)=(pgftransparent!70);color(2cm)=(pgftransparent!100)}
\pgfdeclareradialshading{somenodeshade}{\pgfpointorigin}{%
  color(0mm)=(pgftransparent!0);color(2mm)=(pgftransparent!5);%
  color(5mm)=(pgftransparent!95);color(20mm)=(pgftransparent!100)}
\pgfdeclareradialshading{invertshade}{\pgfpointorigin}{%
  color(0mm)=(pgftransparent!100);color(6mm)=(pgftransparent!95);%
  color(10mm)=(pgftransparent!60);color(2cm)=(pgftransparent!0)}
\pgfdeclarefading{fadeit}{\pgfuseshading{someshade}}
\pgfdeclarefading{fadein}{\pgfuseshading{invertshade}}
%
\begin{document}
\begin{tikzpicture}[projectile/.style={decorate,decoration={random steps,
  segment length=3pt,amplitude=0.5pt}}]
  \fill[black] (-4,-4) rectangle (6,5);
 
  \begin{scope}[xshift=0cm,yshift=-0.4cm,transparency group]
    \pgfsetfading{fadein}{\pgftransformshift{\pgfpointorigin}}
    \foreach \x in {0,6,..., 360}{\draw[blue!80!white,projectile,line width=1.1pt]
      (0,0) to [in=90] (10*rand+\x:rand*1mm+2cm);};
  \end{scope}
 
  \begin{scope}[xshift=2cm,yshift=1cm]
    \foreach \x in {0,8,..., 360}{\draw [yellow!5,thick,projectile] (0.7,0)
      to  (3*rand+\x :1mm*rand+2.2cm)  node[circle,inner sep=1mm,
      shade,shading=somenodeshade,opacity=0.1] {};}
    {\pgfsetfading{fadeit}{\pgftransformshift{\pgfpoint{2.5cm}{1cm}}}};
    \fill[white] (-3,-3) rectangle (3,3);
  \end{scope}
 
  \begin{scope}[xshift=3cm,yshift=-1cm]
    \foreach \x in {0,10,..., 360}{\def\r1{rand}\draw [yellow]
      ($(0,0)!abs{\r1}!(\x :5mm)$) to [in=90] ($(0,0)!abs{\r1}+0.2!(\x :8mm)$);}
    {\pgfsetfading{fadeit}{\pgftransformshift{\pgfpoint{3cm}{-1cm}}}};
    \fill[yellow,opacity=0.6] (-3,-3) rectangle (3,3);
  \end{scope}
 
  \begin{scope}[xshift=-1cm,yshift=1.5cm]
    \foreach \x in {0,12,..., 360}{\def\r2{rand}\draw [red,line width=0.5pt]
      ($(0,0)!abs{\r2}!(\x :3mm)$) -- ($(0,0)!abs{\r2}+0.1!(\x :7mm)$);}
    {\pgfsetfading{fadeit}{\pgftransformshift{\pgfpoint{-1cm}{1.5cm}}}};
    \fill[red,opacity=0.6] (-3,-3) rectangle (3,3);
  \end{scope}
\end{tikzpicture}
\end{document}

The image has been taken from the TeXworks PDF previewer, not all PDF viewers are capable of showing it in this quality. The example has been added to the TikZ example gallery.

Category: TeX.SX, pgf/TikZ | 1 Comment »

Merry Christmas!

Dezember 24th, 2011 by Stefan Kottwitz

Christmas tree

This Christmas tree has been created by Mikko Heiskanen with this code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{scopes,svg.path,shapes.geometric,shadows}
\begin{document}
\begin{tikzpicture}[
  mystar/.style={star, minimum size=2cm, star point ratio=2.5, shade, thick,
    line join=round, color=yellow!80!black, draw=red!20!black,
    top color=yellow!80!white, bottom color=yellow!60!black},
  mytree/.style={scale=0.5, rotate=180, draw=green!60!black, thick,
    line join=round, inner color=green!60!yellow, outer color=green!50!black},
  myball/.style={shade, ball color=#1, circular drop shadow={
    shadow xshift=0pt, shadow yshift=-.5ex, fill=green!40!black}}
  ]
  {[mytree]
  \shadedraw svg "M355,430
    q90,10 105,-85 30,0 50,-30 20,30 50,30 50,-20 100,0 10,88 105,85
    -45,90 -205,25 Q400,520 355,430";
  \shadedraw svg "M380,325
    q83,10 105,-80 25,0 35,-30 20,25 40,30 20,-10 35,-25 20,20 40,25
    25,90 105,82 -15,50 -120,15 -30,-2 -60,12 -30,0 -52,-28
    C490,370 380,360 380,325";
  \shadedraw svg "M435,225
    q65,-8 90,-70 35,40 70,0 25,60 90,70 -30,52 -90,5 -36,48 -73,-3
    C520,254 445,265 435,225";
  \shadedraw svg "M470,139
    q50,5 90,-80 50,90 90,80 -30,30 -50,20 -40,45 -78,0
    Q500,170 470,139";
  }
  %\shadedraw svg[scale=0.5,rotate=180]
  %"M460,532 q50,-8 q77,-45 v-20 a20,13 0 1 1 48,0 v20 q30,40 77,45";
  %pgf/tikz doesn't like the arc operation, as stated in manual
 
  \node[mystar] at (-9.85,-1) {$\lambda$};
 
  \shade[myball=blue]   (-9.7,-2.2)   circle (.2cm);
  \shade[myball=red]    (-9.2,-3.8)   circle (.2cm);
  \shade[myball=green]  (-10.3,-4)    circle (.4cm);
  \shade[myball=yellow] (-8.95,-5.4)  circle (.4cm);
  \shade[myball=red]    (-10.7,-6.1)  circle (.4cm);
  \shade[myball=blue]   (-10.8,-5)    circle (.2cm);
  \shade[myball=yellow] (-9.5,-6.7)   circle (.2cm);
  \shade[myball=green]  (-8.3,-7.6)   circle (.4cm);
  \shade[myball=yellow] (-11.7,-7.6)  circle (.4cm);
  \shade[myball=blue]   (-10.5,-7.8)  circle (.2cm);
\end{tikzpicture}
\end{document}

Further trees based using TikZ and pgfplots, using decorations and L-System fractals are here: Christmas trees with TikZ.

Category: TeX.SX, Events, pgf/TikZ | No Comments »

@TeXgallery on Twitter

Dezember 22nd, 2011 by Stefan Kottwitz

Koch snowflake, TeXgallery Twitter icon
TeXample.net is now on Twitter. TeXample.net is a web site dedicated to TeX and related software, currently it’s focussed on collecting and showing TikZ examples.

Follow @TeXgallery to read about new contributions and site features.

Four TikZ examples have been added this week, more are planned, as well as new site features. Twitter will inform about smaller updates, blog posts about bigger changes.

The @TeXgallery Twitter logo is a Koch snowflake, which can be produced using TikZ:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
\usetikzlibrary[shadings]
\begin{document}
\begin{tikzpicture}
\shadedraw[shading=color wheel] 
  [l-system={rule set={F -> F-F++F-F}, step=2pt, angle=60,
   axiom=F++F++F, order=4}] lindenmayer system -- cycle;
\end{tikzpicture}
\end{document}

This is also one of the recently added examples.

Category: News, pgf/TikZ, Online Ressources | No Comments »

TikZ questions and answers

November 16th, 2010 by Stefan Kottwitz

The {TeX} Q&A site turned out to be a valuable resource regarding TiKZ problems.

For example, during a discussion of ball shadings pictures such as this had been drawn:

go board

There are two open questions, where the best answer will get a reward of site reputation points:

Maybe you are able to answer them? It seems that there are already valuable contributions.

Other examples, which have been answered resp. solved, and which I find interesting, are:

At the moment there are 101 TikZ questions on the site, most of them with several answers. If you have a pgf/TikZ related question, you may ask it there - I’ve seen that there are friendly, capable users who like to deal with TikZ problems.

There’s also the active and helpful pgf-users mailing list.

Category: TeX.SX, pgf/TikZ, Online Ressources, Graphics | No Comments »

More on TikZ tables

April 30th, 2010 by Stefan Kottwitz

At present I don’t have much time for the blog because of my work, but I keep on reading and answering questions and comments.

For instance since I’ve noticed a link by Uwe to a table related topic and because of Oliviers comment there I’ve added another comment to “Fancy tables with TikZ“. It shows a tikz-matrix based table, seperating the actual implementation from the table contents. A simple code like

\begin{mytable}{1.2cm}{2.4cm}{1.2cm}{0.6cm}{
   \head{Rank} & \head{Distribution} & \head{Hits} & \\
   1 & Ubuntu & 2114 & \down \\
   2 & Fedora & 1451 & \up   \\
             ...
  10 & Arch   &  625 & \down \\
}
\end{mytable}

produces the following output.

table with TikZ

Changing the style of tables in the whole document is easier when they are defined as new environments in the preamble. For instance the mytable environment could be implemented without TikZ using just the standard tabular environment without changing the usage of those tables. Likewise with \head - I avoid using \textbf directly. It allows to change the look of the headings in a consistent way by formatting logically.

Comments and suggestions are always welcome, perhaps following the original post “Fancy tables with TikZ“.

Category: pgf/TikZ, Graphics | 1 Comment »

Fancy tables with TikZ

August 26th, 2009 by Stefan Kottwitz

Today I wanted to create a table for a presentation and I remembered a suggestion made by Kjell Magne Fauske in comp.text.tex in August 2008, to use TikZ to create tables with rounded corners. I’ve investigated this idea further to achieve a colorful table layout in a shape that’s unusual for LaTeX. Here’s the result, displaying a ranking of Linux distributions produced by DistroWatch.com:

fancy tables with TikZ

Click on the image to see it bigger, for a complete view open the pdf presentation.

The table has been put into a TikZ node, both at the top and at the bottom of the table I’ve used rectangles with rounded corners and some shading. A third rectangle is used to overlay parts of the other two rectangles.

The complete source code:

\documentclass{beamer}
\usetheme{default}
\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{tikz}
\usetikzlibrary{calc}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\setbeamertemplate{background canvas}[vertical shading]%
  [top=blue!1,bottom=blue!30]
\setbeamertemplate{navigation symbols}{}
\newcommand*\up{\textcolor{green}{%
  \ensuremath{\blacktriangle}}}
\newcommand*\down{\textcolor{red}{%
  \ensuremath{\blacktriangledown}}}
\newcommand*\const{\textcolor{darkgray}%
  {\textbf{--}}}
\begin{document}
\begin{frame}[bg=lightgray]
\textbf{\Large Linux distribution ranking,
        26th August 2009}
\begin{center}
\begin{tikzpicture}
\node (tbl) {
\begin{tabularx}{.6\textwidth}{cXrcc}
\arrayrulecolor{purple}
\textbf{Rank} & \textbf{Distribution} &
  \textbf{Hits} & \\
1 & Ubuntu\rule{0pt}{2.5ex}  &  2114 & \down \\
\midrule
2 & Fedora & 1451 & \up \\
\midrule
3 & Mint & 1297 & \const \\
\midrule
4 & OpenSUSE & 1228 & \up \\
\midrule
5 & Debian & 910 & \down \\
\midrule
6 & Mandriva & 907 & \up \\
\midrule
7 & PCLinuxOS & 764 & \up \\
\midrule
8 & Puppy & 738 & \up \\
\midrule
9 & Sabayon & 671 & \up \\
\midrule
10 & Arch & 625 & \down \\[0.5ex]
\end{tabularx}};
\begin{pgfonlayer}{background}
\draw[rounded corners,top color=red,bottom color=black,
    draw=white] ($(tbl.north west)+(0.14,0)$)
    rectangle ($(tbl.north east)-(0.13,0.9)$);
\draw[rounded corners,top color=white,bottom color=black,
    middle color=red,draw=blue!20] ($(tbl.south west)
    +(0.12,0.5)$) rectangle ($(tbl.south east)-(0.12,0)$);
\draw[top color=blue!1,bottom color=blue!20,draw=white]
    ($(tbl.north east)-(0.13,0.6)$)
    rectangle ($(tbl.south west)+(0.13,0.2)$);
\end{pgfonlayer}
\end{tikzpicture}
\end{center}
\small
Data by DistroWatch.com, spanning over the last 6 months,
hits per day.
\end{frame}
\end{document}

It’s just a draft, some lengths have been adjusted to fit in order to demonstrate using TikZ with tables in a quick way.

Category: pgf/TikZ, Figures and Tables, Graphics | 19 Comments »

Tutorial: Commutative Diagrams using TikZ

Februar 4th, 2009 by Stefan Kottwitz

In previous posts I’ve shown some examples how the TikZ graphics package could be used to draw mathematical diagrams like exact sequences and commutative diagrams. Felix Lenders has written a tutorial called Commutative Diagrams using TikZ dealing with this subject and has published it today. In that paper he’s describing basic syntax, styles, arrows, curves, positioning issues and more. The tutorial contains several examples with the corresponding source code.

To read related blog posts have a look at the TikZ category.

Category: News, pgf/TikZ, Mathematics | 5 Comments »

Math formulas and arrows with TikZ

Januar 19th, 2009 by Stefan Kottwitz

In the Art of Problem Solving Forum somebody asked for help in creating a construction for proofs and demonstrations in Logic by LaTeX commands. Math expressions should be aligned, some connected by arrows going vertically and horizontally.
Regarding arrows I would use tikz and also its matrix library for math nodes. The nodes could be connected by -| or |- path construction operations, like

\draw (node1) -| (node2) |- (node3);

For creation of the example given in the thread on AoPS I’ve used a matrix of math nodes, some empty nodes for alignment and |- -| arrows, here’s the compilable example code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[every node/.style={anchor=west}]
  \matrix (m) [matrix of math nodes,
    nodes in empty cells]{
    \quad & 1.\quad (x)(Q\supset Fx) & \\
    & 2.\quad Q\supset Fx & \textrm{I,\textbf{UI}} & \\
    & 3.\quad Q \\
    & 4.\quad Fx & 2, 3, \textrm{ M.P.}\\
    & 5.\quad (x)Fx & 4, \textrm{ \textbf{UG}} \\
    & 6.\quad Q\supset(x)Fx & 3-5, \textrm{ C.P.} \\
    & 7.\quad \parbox[t]{2.9cm}{%
             $(x)(Q\supset(x)Fx)\supset$\\
             $[Q\supset(x)Fx]$} & 1-6, \textrm{ C.P.}\\};
  \draw[-stealth] (m-7-2.north east)
               -| (m-1-1.west) |- (m-1-2);
  \draw[-stealth] (m-6-2.north east)
               -| (m-3-1.east) |- (m-3-2);
\end{tikzpicture}
\end{document}

Output:

logic diagram with TikZ

Category: pgf/TikZ, Mathematics | 1 Comment »