Diagrams and Tables — mermaid, tikzgraph, tikzcd, tabular
A complete guide to diagrams and tables on Folio. Covers mermaid flowcharts and sequence diagrams, tikzgraph for graph drawing, tikzcd for commutative diagrams, tabular for tables, figure/table environments, and includegraphics.
1. Mermaid Diagrams
Folio provides a mermaid environment for text-based diagrams. This is a Folio-specific feature not available in standard LaTeX.
1.1. Flowcharts
\begin{mermaid}
graph TD
A[Start] --> B{Condition}
B -->|Yes| C[Process 1]
B -->|No| D[Process 2]
C --> E[End]
D --> E
\end{mermaid}
Result:
graph TD
A[Start] --> B{Condition}
B -->|Yes| C[Process 1]
B -->|No| D[Process 2]
C --> E[End]
D --> E1.2. Horizontal Flowcharts
Use graph LR for left-to-right flow:
\begin{mermaid}
graph LR
A[Input] --> B[Preprocessing]
B --> C[Model]
C --> D[Postprocessing]
D --> E[Output]
\end{mermaid}
Result:
graph LR
A[Input] --> B[Preprocessing]
B --> C[Model]
C --> D[Postprocessing]
D --> E[Output]1.3. Sequence Diagrams
\begin{mermaid}
sequenceDiagram
participant C as Client
participant S as Server
participant D as Database
C->>S: HTTP Request
S->>D: Query
D-->>S: Result
S-->>C: Response
\end{mermaid}
Result:
sequenceDiagram
participant C as Client
participant S as Server
participant D as Database
C->>S: HTTP Request
S->>D: Query
D-->>S: Result
S-->>C: Response1.4. Use Case: Dependency Diagrams
Useful for showing topic dependencies in textbook series:
\begin{mermaid}
graph TD
A["Sets and Maps"] --> B["Group Definition"]
B --> C["Subgroups"]
B --> D["Homomorphisms"]
C --> E["Cosets"]
E --> F["Normal Subgroups"]
F --> G["Quotient Groups"]
D --> G
G --> H["Isomorphism Theorems"]
style A fill:#f5f5f5,stroke:#333,color:#000
style H fill:#f5f5f5,stroke:#333,color:#000
\end{mermaid}
Result:
graph TD
A["Sets and Maps"] --> B["Group Definition"]
B --> C["Subgroups"]
B --> D["Homomorphisms"]
C --> E["Cosets"]
E --> F["Normal Subgroups"]
F --> G["Quotient Groups"]
D --> G
G --> H["Isomorphism Theorems"]
style A fill:#f5f5f5,stroke:#333,color:#000
style H fill:#f5f5f5,stroke:#333,color:#000
2. tikzgraph: Graph Drawing
The tikzgraph environment draws graph-theory graphs (vertices and edges). It uses a syntax unified with LaTeX notation for undirected and directed graphs. This is a Folio-specific environment.
2.1. Basic Syntax
Define vertices with id or id/$label$, connect with --, and separate edge chains with ;:
\begin{tikzgraph}
a/$v_1$ -- b/$v_2$ -- c/$v_3$;
a -- c;
\end{tikzgraph}
Result:
Omitting the label displays the vertex ID as-is:
\begin{tikzgraph}
a -- b -- c;
\end{tikzgraph}
Result:
2.2. Directed Graphs
Use -> for directed edges, <- for reverse, and <-> for bidirectional:
\begin{tikzgraph}
a/$v_1$ -> b/$v_2$ -> c/$v_3$;
c -> a;
\end{tikzgraph}
Result:
2.3. Edge Styles and Labels
Use square brackets for edge styles (dashed, dotted, thick, double) and labels:
\begin{tikzgraph}
a/$u$ --[dashed] b/$v$;
a --[thick, "3"] c/$w$;
b --[dotted] c;
\end{tikzgraph}
Result:
2.4. Layouts
Choose a layout with the environment option. Default is spring layout (force-directed); circular layout arranges vertices in a circle:
\begin{tikzgraph}[circular layout]
a/$1$ -- b/$2$ -- c/$3$ -- d/$4$ -- e/$5$ -- a;
\end{tikzgraph}
Result:
2.5. Syntax Summary
| Syntax | Meaning |
a -- b |
Undirected edge |
a -> b |
Directed edge () |
a <- b |
Reverse edge () |
a <-> b |
Bidirectional edge |
a/$v_1$ |
Vertex with KaTeX label |
--[dashed] |
Dashed style |
--[dotted] |
Dotted style |
--[thick] |
Thick style |
--[double] |
Double-line style |
--["label"] |
Edge label |
[spring layout] |
Force-directed layout (default) |
[circular layout] |
Circular layout |
2.6. Multi-Edges
Defining multiple edges between the same pair automatically draws them as curves:
\begin{tikzgraph}
A -- B; A -- B;
A -- C; A -- C;
A -- D;
B -- D;
C -- D;
\end{tikzgraph}
Result (Bridges of Kö
2.7. Subgraphs
Use {label: ...} to define subgraphs. Nodes within a subgraph are enclosed in a dashed border:
\begin{tikzgraph}
{SCC $C_1$: a -> b -> c -> a;}
{SCC $C_2$: d -> e -> d;}
{SCC $C_3$: f;}
c -> d;
e -> f;
\end{tikzgraph}
Result:
Use {a -- b;} without a colon for an unlabeled subgraph.
2.8. Differences from Real TikZ
tikzgraph bears a TikZ-like name but is a Folio-specific simplified graph drawing environment, quite different from real TikZ:
| Feature | tikzgraph | TikZ |
| Coordinate specification | Auto-layout only | Arbitrary coordinates |
| Node shapes | Circle only | Rectangle, ellipse, polygon, etc. |
| Color specification | Not supported | Fully customizable |
| Label positioning | Inside node only | above, below, left, right |
| Edge curves | Auto for multi-edges | bend left/right, out/in angles |
\foreach loops |
Not supported | Supported |
| Decorations | Not supported | snake, zigzag, etc. |
tikzgraph is specialized for basic graph-theory graph drawing. If you need custom node shapes or colors, consider using the mermaid environment instead.
3. tikzcd: Commutative Diagrams
The tikzcd environment draws commutative diagrams, useful for category-theoretic diagrams in math articles.
3.1. Basic Commutative Diagrams
\begin{tikzcd}
A \arrow[r, "f"] \arrow[d, "g"'] & B \arrow[d, "h"] \\
C \arrow[r, "k"'] & D
\end{tikzcd}
Result:
3.2. Arrow Types
\begin{tikzcd}
A \arrow[r, "f"] & B % Regular morphism
A \arrow[r, hookrightarrow] & B % Injection
A \arrow[r, twoheadrightarrow] & B % Surjection
A \arrow[r, dashed] & B % Dashed
\end{tikzcd}
Result:
3.3. Exact Sequences
A short exact sequence:
\begin{tikzcd}
0 \arrow[r] & A \arrow[r, "f"] & B \arrow[r, "g"] & C \arrow[r] & 0
\end{tikzcd}
Result:
3.4. Complex Commutative Diagrams
\begin{tikzcd}
& A \arrow[dl, "p"'] \arrow[dr, "q"] & \\
B \arrow[dr, "f"'] & & C \arrow[dl, "g"] \\
& D &
\end{tikzcd}
Result:
4. Tables (tabular Environment)
4.1. Basic Tables
\begin{tabular}{lcc}
\hline
Name & Symbol & Order \\
\hline
Cyclic group & $\mathbb{Z}/n\mathbb{Z}$ & $n$ \\
Symmetric group & $S_n$ & $n!$ \\
Dihedral group & $D_n$ & $2n$ \\
\hline
\end{tabular}
Result:
| Name | Symbol | Order |
| Cyclic group | ||
| Symmetric group | ||
| Dihedral group |
4.2. Column Alignment
Use l (left), c (center), r (right):
\begin{tabular}{|l|c|r|}
\hline
Left & Center & Right \\
\hline
apple & banana & cherry \\
dog & elephant & fox \\
\hline
\end{tabular}
Result:
| Left | Center | Right |
| apple | banana | cherry |
| dog | elephant | fox |
5. figure and table Environments
Use float environments for captions and numbering:
\begin{figure}
\centering
\begin{tikzcd}
A \arrow[r, "f"] \arrow[d, "g"'] & B \arrow[d, "h"] \\
C \arrow[r, "k"'] & D
\end{tikzcd}
\caption{Example of a commutative diagram}
\label{fig:commutative}
\end{figure}
Figure \ref{fig:commutative} shows the basic form of a commutative diagram.
Result:
Figure 1 shows the basic form of a commutative diagram.
\begin{table}
\centering
\begin{tabular}{lcc}
\hline
Group & Commutativity & Finiteness \\
\hline
$(\mathbb{Z}, +)$ & Abelian & Infinite \\
$S_3$ & Non-abelian & Finite \\
$(GL_2(\mathbb{R}), \cdot)$ & Non-abelian & Infinite \\
\hline
\end{tabular}
\caption{Classification of groups}
\label{tab:groups}
\end{table}
Table \ref{tab:groups} shows a basic classification of groups.
Result:
| Group | Commutativity | Finiteness |
| Abelian | Infinite | |
| Non-abelian | Finite | |
| Non-abelian | Infinite |
Table 1 shows a basic classification of groups.
6. Images
The \includegraphics command works if you specify an image URL directly:
\includegraphics[width=0.8\textwidth]{https://example.com/image.png}
width option is supported. Local file paths cannot be used, so you must specify a publicly accessible URL. For creating diagrams from text, mermaid, tikzgraph, and tikzcd are recommended.
7. Summary
On Folio, you can draw text-based diagrams with mermaid (flowcharts, etc.), tikzgraph (graph-theory graphs), and tikzcd (commutative diagrams). The tabular environment for tables works as expected. Next, we'll cover cross-references, links, and custom commands.
Mathematics "between the lines" — exploring the intuition textbooks leave out, written in LaTeX on Folio.