PGF/TikZ: Difference between revisions

From miki
Jump to navigation Jump to search
 
(23 intermediate revisions by the same user not shown)
Line 7: Line 7:
** [http://www.ctan.org/tex-archive/graphics/pgf/base/doc/generic/pgf/pgfmanual.pdf {{pgftikz}} manual] (see also {{file|pgfmanual.pdf.gz}} in debian package {{deb|pgf}})
** [http://www.ctan.org/tex-archive/graphics/pgf/base/doc/generic/pgf/pgfmanual.pdf {{pgftikz}} manual] (see also {{file|pgfmanual.pdf.gz}} in debian package {{deb|pgf}})
* [http://www.texample.net/tikz/examples/ {{pgftikz}} gallery at TeXample.net] (impressive set of examples!!!)
* [http://www.texample.net/tikz/examples/ {{pgftikz}} gallery at TeXample.net] (impressive set of examples!!!)
* [http://www.iacr.org/authors/tikz/ TikZ for Cryptographers]

;Packages
* [http://altermundus.com/ tkz-euclide] An extremely '''simple and powerful''' drawing package for drawing geometry figures.
** The link to the (older) french version of the site [[http://altermundus.fr/pages/download.html tkz-euclide] ]
* [http://mirror.hmc.edu/ctan/graphics/pgf/contrib/tikzpeople/tikzpeople.pdf tikzpeople]


== Reference ==
== Reference ==
Line 21: Line 27:
\node [below=5pt of c] (d) {D};
\node [below=5pt of c] (d) {D};
\draw[postaction={decorate}] (c) to [out=0,in=0,looseness=3] (d);
\draw[postaction={decorate}] (c) to [out=0,in=0,looseness=3] (d);
\end{tikzpicture}
</source>

;Trouble in labels
Better enclose label text in curly braces:
<source lang=latex>
% ...
\node[mult] (m) [label=right:{$\rsam$}] {};
% ...
\matrix [matrix of math nodes]
{
|(m1) [label=left:{\dagnode_1=1}]| {} \\
};

</source>

== TKZ-Euclide ==

=== Quick references ===

TikZ options
* '''Placement''': <code>below</code>, <code>above</code>, <code>left</code>, <code>right</code>, <code>below left</code>, <code>below right</code>, <code>above left</code>, <code>above right</code>.
* '''line width''': <code>thick</code>, <code>very thick</code>.
* '''color''': <code>black</code>, <code>red</code>, <code>blue</code>, <code>green</code>, <code>purple</code>, <code>purple!10</code>...

Package loading:
<source lang=latex>
\usepackage[usenames,dvipsnames,svgnames]{xcolor} % before tikz or tkz
\usepackage{tkz-euclide} % Add 'tkz-tab' and/or 'tkz-fct' if needed
\usetkzobj{all}
</source>

Overall setup (in document preamble):
<source lang=latex>
\definecolor{Maroon}{rgb}{0.5,0.0,0.0}%{.80,.80,.95}
\definecolor{fondpaille}{cmyk}{0,0,0.1,0}
\tkzSetUpColors[background=fondpaille,text=Maroon] % Setup default background / foreground colors
</source>

Create a drawing and set options (optional):
<source lang=latex>
\begin{tikzpicture}[scale=1.5] % Set drawing scale
% ...
\end{tikzpicture}

\begin{tikzpicture}[label style/.style={font=\Large}] % Set label style
% ...
\end{tikzpicture}
</source>

Drawing setup, clipping and grid:
<source lang=latex>
\definecolor{bistre}{rgb}{.75,.50,.30} % In preamble, if using sub-grid

\begin{tikzpicture}
\tkzInit[ymin=-1,ymax=5,xmin=-1,xmax=5]
\tkzAxeXY % Before clipping, or won't appear
\tkzClip % Or \tkzClip[space=1] to add space around grid
\tkzGrid[sub,color=bistre,subxstep=.2,subystep=.2]
% ...
\end{tikzpicture}
</source>

Define points:
<source lang=latex>
\tkzDefPoint(0,0){A} % Absolute coordinates
\tkzDefPoint(90:2){B} % Polar (angle:radius) coordinates
</source>

Options for <code>\tkzDefPoint</code>:
<source lang=latex>
\tkzDefPoint[label=above:A](80:2){A} % Add a label to point (but can we change label style?)
</source>

Options for <code>\tkzDrawPoints</code>:
<source lang=latex>
\tkzDrawPoints[color=black](O,A,B,C) % Set line color
\tkzDrawPoints[fill=black](O,A,B,C) % Set fill color
\tkzDrawPoints[size=10](O,A,B,C) % Set point size
</source>

Options for <code>\tkzMarkAngle</code>:
<source lang=latex>
\tikzset{
myangle/.style={size=0.6,fill=purple,opacity=0.1,mkpos=.2}, % In preamble. mkpos needed to fix 'Dimension too large'
}

\tkzMarkAngle[size=0.6](A,O,B) % Set size
\tkzMarkAngle[fill=purple](A,O,B) % Set fill
\tkzMarkAngle[opacity=0.1](A,O,B) % Set fill opacity (not the same as 'fill=purple!10')
\tkzMarkAngle[myangle](A,O,B) % Set fill opacity (not the same as 'fill=purple!10')
</source>

Options for <code>\tkzLabelAngle</code>:
<source lang=latex>
\tkzLabelAngle[pos=-0.4](A,C,B){$\alpha$} %Set negative position (outwards)
\tkzLabelAngle[pos=0.5,font=\tiny](A,C,B){$\alpha$} %Set font size
</source>

Some interesting commands:
<source lang=latex>
\tkzMarkRightAngle(B,A,C) % Mark a right angle
\tkzDrawPolygon(A,B,C) % Instead of \tkzDrawSegments(A,B B,C C,A)
</source>

=== Examples ===

In this example [http://tex.stackexchange.com/questions/204479/how-can-i-label-points-in-tkz-euclide-without-serifes],
* Clip image to a circle using <code>\tkzClipCircle(O,Z)</code>
* Label angles using <code>\tkzLabelAngle[pos=0.2](B,A,C){$\alpha$}</code>
* Label points, with positioning, using <code>\tkzLabelPoints[below left](B)</code>
* Change text style globally, using <code>label style/.append style={font=\sansmath}</code>
* Change drawing scale, using <code>scale=3</code>
* Draw points, with style, using <code>\tkzDrawPoints[color=black,fill=red,size=5](A,B,C)</code>.

<source lang=latex>
\begin{tikzpicture}[scale=3,label style/.append style={font=\sansmath}]
\tkzDefPoint(0,0){O}
\tkzDefPoint(1,0){Z}

% Define points
\tkzDefPoint(-0.7,-0.1){A}
\tkzDefPoint(0.4,-0.3){B}
\tkzDefPoint(0.1,0.4){C}

% Draw big circle
\tkzDrawCircle[fill=white](O,Z)

% I have no idea what this does,
% but when I remove it the rest of the image (the big circles)
% get visible. So it seems to crop the image to the size of the circle
\tkzClipCircle(O,Z)

% Draw angles
\tkzMarkAngles[fill= orange,size=0.3cm,opacity=.3](B,A,C)
\tkzLabelAngle[pos=0.2](B,A,C){$\alpha$}

\tkzMarkAngles[fill= orange,size=0.3cm,opacity=.3](C,B,A)
\tkzLabelAngle[pos=0.2](C,B,A){$\beta$}

\tkzMarkAngles[fill= orange,size=0.3cm,opacity=.3](A,C,B)
\tkzLabelAngle[pos=0.2](A,C,B){$\gamma$}


% "Clip" angles
\tkzDrawCircle[fill,orthogonal through=A and B,color=white](O,Z)
\tkzDrawCircle[fill,orthogonal through=A and C,color=white](O,Z)
\tkzDrawCircle[fill,orthogonal through=B and C,color=white](O,Z)

% Draw big circle
\tkzDrawCircle(O,Z)

% Draw lines
\tkzDrawCircle[orthogonal through=A and B,color=green](O,Z)
\tkzDrawCircle[orthogonal through=A and C,color=blue](O,Z)
\tkzDrawCircle[orthogonal through=B and C,color=red](O,Z)

% Draw points and label them
\tkzDrawPoints[color=black,fill=red,size=5](A,B,C)
\tkzLabelPoints[below](A)
\tkzLabelPoints[below left](B)
\tkzLabelPoints[above left](C)
\end{tikzpicture}
\end{tikzpicture}
</source>
</source>

Latest revision as of 08:28, 27 April 2017

PGF/TikZ is a powerful drawing package that can be used to produce professional-looking graphics. In particular PGF/TikZ interpreter can be used from LaTeX documents.

Links

Packages
  • tkz-euclide An extremely simple and powerful drawing package for drawing geometry figures.
    • The link to the (older) french version of the site [tkz-euclide ]
  • tikzpeople

Reference

To be completed.

Troubleshoot

markings decoration not show in curved path

Setting a decoration at position 1 does not work when using curved paths. An easy fix is to use 0.999 instead (see also bug, [1]).

\begin{tikzpicture}[node distance=1cm,
    decoration={markings, mark=at position 0.999 with {\arrow[scale=2]{stealth}}}]
  \node (c) {C};
  \node [below=5pt of c] (d) {D};
  \draw[postaction={decorate}] (c) to [out=0,in=0,looseness=3] (d);
\end{tikzpicture}
Trouble in labels

Better enclose label text in curly braces:

% ...
\node[mult]                   (m)   [label=right:{$\rsam$}] {};
% ...
\matrix [matrix of math nodes]
{
  |(m1) [label=left:{\dagnode_1=1}]| {} \\
};

TKZ-Euclide

Quick references

TikZ options

  • Placement: below, above, left, right, below left, below right, above left, above right.
  • line width: thick, very thick.
  • color: black, red, blue, green, purple, purple!10...

Package loading:

\usepackage[usenames,dvipsnames,svgnames]{xcolor}      % before tikz or tkz
\usepackage{tkz-euclide}                               % Add 'tkz-tab' and/or 'tkz-fct' if needed
\usetkzobj{all}

Overall setup (in document preamble):

\definecolor{Maroon}{rgb}{0.5,0.0,0.0}%{.80,.80,.95}
\definecolor{fondpaille}{cmyk}{0,0,0.1,0}
\tkzSetUpColors[background=fondpaille,text=Maroon]     % Setup default background / foreground colors

Create a drawing and set options (optional):

\begin{tikzpicture}[scale=1.5]                         % Set drawing scale
% ...
\end{tikzpicture}

\begin{tikzpicture}[label style/.style={font=\Large}]  % Set label style
% ...
\end{tikzpicture}

Drawing setup, clipping and grid:

\definecolor{bistre}{rgb}{.75,.50,.30}              % In preamble, if using sub-grid

\begin{tikzpicture}
\tkzInit[ymin=-1,ymax=5,xmin=-1,xmax=5]
\tkzAxeXY                                           % Before clipping, or won't appear
\tkzClip                                            % Or \tkzClip[space=1] to add space around grid 
\tkzGrid[sub,color=bistre,subxstep=.2,subystep=.2]
% ...
\end{tikzpicture}

Define points:

\tkzDefPoint(0,0){A}                      % Absolute coordinates
\tkzDefPoint(90:2){B}                     % Polar (angle:radius) coordinates

Options for \tkzDefPoint:

\tkzDefPoint[label=above:A](80:2){A}     % Add a label to point (but can we change label style?)

Options for \tkzDrawPoints:

\tkzDrawPoints[color=black](O,A,B,C)  % Set line color
\tkzDrawPoints[fill=black](O,A,B,C)   % Set fill color
\tkzDrawPoints[size=10](O,A,B,C)      % Set point size

Options for \tkzMarkAngle:

\tikzset{
  myangle/.style={size=0.6,fill=purple,opacity=0.1,mkpos=.2},       % In preamble. mkpos needed to fix 'Dimension too large'
}

\tkzMarkAngle[size=0.6](A,O,B)           % Set size
\tkzMarkAngle[fill=purple](A,O,B)        % Set fill
\tkzMarkAngle[opacity=0.1](A,O,B)        % Set fill opacity (not the same as 'fill=purple!10')
\tkzMarkAngle[myangle](A,O,B)            % Set fill opacity (not the same as 'fill=purple!10')

Options for \tkzLabelAngle:

\tkzLabelAngle[pos=-0.4](A,C,B){$\alpha$}            %Set negative position (outwards)
\tkzLabelAngle[pos=0.5,font=\tiny](A,C,B){$\alpha$}  %Set font size

Some interesting commands:

\tkzMarkRightAngle(B,A,C)               % Mark a right angle
\tkzDrawPolygon(A,B,C)                  % Instead of \tkzDrawSegments(A,B B,C C,A)

Examples

In this example [2],

  • Clip image to a circle using \tkzClipCircle(O,Z)
  • Label angles using \tkzLabelAngle[pos=0.2](B,A,C){$\alpha$}
  • Label points, with positioning, using \tkzLabelPoints[below left](B)
  • Change text style globally, using label style/.append style={font=\sansmath}
  • Change drawing scale, using scale=3
  • Draw points, with style, using \tkzDrawPoints[color=black,fill=red,size=5](A,B,C).
\begin{tikzpicture}[scale=3,label style/.append style={font=\sansmath}]
    \tkzDefPoint(0,0){O}
    \tkzDefPoint(1,0){Z}

    % Define points
    \tkzDefPoint(-0.7,-0.1){A}
    \tkzDefPoint(0.4,-0.3){B}
    \tkzDefPoint(0.1,0.4){C}

    % Draw big circle
    \tkzDrawCircle[fill=white](O,Z)

    % I have no idea what this does,
    % but when I remove it the rest of the image (the big circles)
    % get visible. So it seems to crop the image to the size of the circle
    \tkzClipCircle(O,Z)

    % Draw angles
    \tkzMarkAngles[fill= orange,size=0.3cm,opacity=.3](B,A,C)
    \tkzLabelAngle[pos=0.2](B,A,C){$\alpha$}

    \tkzMarkAngles[fill= orange,size=0.3cm,opacity=.3](C,B,A)
    \tkzLabelAngle[pos=0.2](C,B,A){$\beta$}

    \tkzMarkAngles[fill= orange,size=0.3cm,opacity=.3](A,C,B)
    \tkzLabelAngle[pos=0.2](A,C,B){$\gamma$}


    % "Clip" angles
    \tkzDrawCircle[fill,orthogonal through=A and B,color=white](O,Z)
    \tkzDrawCircle[fill,orthogonal through=A and C,color=white](O,Z)
    \tkzDrawCircle[fill,orthogonal through=B and C,color=white](O,Z)

    % Draw big circle
    \tkzDrawCircle(O,Z)

    % Draw lines
    \tkzDrawCircle[orthogonal through=A and B,color=green](O,Z)
    \tkzDrawCircle[orthogonal through=A and C,color=blue](O,Z)
    \tkzDrawCircle[orthogonal through=B and C,color=red](O,Z)

    % Draw points and label them
    \tkzDrawPoints[color=black,fill=red,size=5](A,B,C)
    \tkzLabelPoints[below](A)
    \tkzLabelPoints[below left](B)
    \tkzLabelPoints[above left](C)
\end{tikzpicture}