This repository shares TikZ and PGF coding (written by Ian He and JaeSeok Oh) to create plots in LaTeX. To see the coding for any plot in the following sections, please click the figure. The hyperlink will lead you to our corresponding tex file.
Contact:
🥸 Ian: [email protected].
😎 JaeSeok: [email protected].
Comments are always welcomed!
TikZ and PGF are languages commonly used in LaTeX for producing vector graphics, with lots of wonderful features including the drawing of points, lines, arrows, and shapes. More precisely, PGF is a lower-level language, while TikZ is a set of higher-level macros that use PGF.
To replicate the plots we create in the following sections, you must type the codes below in your LaTeX preamble.
\usepackage{graphicx, float, caption, subcaption, tzplot, asymptote, pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{calc, calligraphy, decorations.pathreplacing, fit, patterns, shadows, shapes.geometric, shapes.misc}
\usepackage{xcolor}
\definecolor{main}{RGB}{0,166,82}
\definecolor{second}{RGB}{32,178,170}
\usepackage{amsmath, amssymb, bbm, dutchcal}
Note:
- The
graphicx
package (documentation) provides some useful optional arguments to the\includegraphics
command. - The
float
package (documentation) improves the interface for defining floating objects, such as figures and tables. By default, we can use something[h]
(here),t
(top), andb
(bottom) to determine the figure positioning; however, these positioning options are not strong --- LaTeX still has some flexibility to select the best position in its mind. To precisely fix the position of a floating objects, we have to use the parameter[H]
fromfloat
. - The
caption
(documentation) andsubcaption
(documentation) packages allow us to customize the captions and subcaptions in floating environments like figure, table, subfigure, and subtable. - The
tzplot
package (documentation) provides some TikZ-based macros to make it easy to draw graphs. For example,- The
\tzaxes
command draws the x-axis and the y-axis quickly. - The
\tzfn
command plots a function over a specified domain. - The
\tzbezier
command draws a Bézier curve with one or two control points from the first coordinate to the last coordinate. - The
\tzdot
and\tzcdot
commands add a label to a dot (with two optional patterns and two optional sizes).
- The
- The
asymptote
package (documentation) provides a lot of commands for 2D and 3D high-quality level technical drawing. - The
pgfplots
package (documentation) allows us to draw high-quality function plots. In particular, it supports axis scaling, axis ticks custimization, axis labels custimization, legend entries, etc. Note thatpgfplots
has been written with backwards compatibility; thus, new features occasionally lead to a different behavior. Therefore, we suggest to activate explicitly new features or bugfixes by writing\pgfplotsset{compat=1.18}
in your preamble, wherecompat=1.18
is the highest compatibility level nowadays. The lowest level iscompat=1.3
. asymptote
andpgfplots
provide basic functionalities and load thetikz
andpgf
packages (documentation) automatically. For special features, special libraries must be included. The libraries we use includecalc
(making complex coordinate calculations);calligraphy
(enabling calligraphic style drawings);decorations.pathreplacing
(defining decorations that replace the to-be-decorated path by another path);fit
(defining options for fitting a node so that it contains a set of coordinates);patterns
(providing different patterns for filling in area);shadows
(helping add a partly transparent shadow to a path or node);shapes.geometric
(defining some shapes such as ellipses and polygons);shapes.misc
(defining additional shapes).
- The
xcolor
package (documentation) allows us to select colors for hyper references, url links, plotting figures, etc. The basic color (e.g., blue and red) can be used directly by typing\color{color_name}
to use it in the document. If additional colors are needed, we suggest to name the color first (for convenient future use) by the\definecolor{new_color_name}{RGB}{#,#,#}
command, and then use the\color{new_color_name}
command. The RGB model is our preferred model, but other models (e.g.,rgb
,HTML
,HSB
, etc.) are also available. There are some good websites to search for color codes: - The
amsmath
package (documentation) is a principal package for mathematical typesetting. Onceamsmath
is loaded, the packagesamsbsy
(for bold symbols),amsopn
(for operator names) andamstext
(for text embedded in mathematics) are also loaded. - The
amssymb
package provides an extended symbol collection, especially including some additional binary relation symbols (e.g.,\boxdot
,\boxplus
,\boxtimes
). Something noteworthy is that this package provides the\mathbb{ }
command for producing blackboard bold characters. - The
bbm
package (documentation) provides blackboard variants of characters in math mode. The command is\mathbbm{ }
, which produces the blackboard bold characters slighly different from those produced by\mathbb{ }
. - The
dutchcal
package (documentation) reworks the mathematical calligraphic font ESSTIX13 in the packageesstix
(documentation) and adds a bold version.