Skip to content

Instantly share code, notes, and snippets.

@rmurphy2718
Last active June 10, 2019 20:06
Show Gist options
  • Save rmurphy2718/2681f710e37a40d157cf68ee348187b9 to your computer and use it in GitHub Desktop.
Save rmurphy2718/2681f710e37a40d157cf68ee348187b9 to your computer and use it in GitHub Desktop.
Latex: Graphs, Subfigures, and Captions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ryan Murphy
%
% This latex shows:
% (1) How to make graphs using tikz
% (2) How to align them as subfigures in a grid
% (3) Use subfigure-level and figure-level captions
% (4) Include a description
% (5) Reference the figure
%
% It was put together using more StackExchange and web examples than I can individually acknowledge here, but I appreciate them nonetheless!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\documentclass{article}
\usepackage[latin9]{inputenc}
\usepackage{subcaption}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{tkz-graph}
\usetikzlibrary{positioning}
\begin{document}
This sentence references Figure~\ref{fig:GraphsAndLabeling}.
\begin{figure}[h]
\centering
%
% ~~~~~~~ FIRST SUBFIGURE
%
\begin{subfigure}[b]{0.3\linewidth}
\subcaptionbox{}{%
\begin{tikzpicture}[auto,node distance=3cm, thick, main node/.style={circle,draw,font=\sffamily\bfseries}]
\node[main node] (3) at (0,0) {};
\node[main node] (4) at (2,0) {};
\node[main node] (1) at (0,2) {};
\node[main node] (2) at (2,2) {};
\path (1) edge node{} (2);
\path (2) edge node{} (4);
\path (4) edge node{} (3);
\path (3) edge node{} (1);
\end{tikzpicture}
}
\end{subfigure}%
\\
%
% ~~~~~~~ SECOND SUBFIGURE
%
\begin{subfigure}[b]{0.3\linewidth}
\subcaptionbox{}{%
\begin{tikzpicture}[auto,node distance=3cm, thick, main node/.style={circle,draw,font=\sffamily\bfseries}]
\node[main node] (3) at (0,0) {};
\node[main node] (1) at (0,2) {};
\node[main node] (2) at (2,2) {};
\path (1) edge node{} (2);
\path (3) edge node{} (1);
\end{tikzpicture}
}
\end{subfigure}
%
% ~~~~~~~ THIRD SUBFIGURE
%
\begin{subfigure}[b]{0.3\linewidth}
\subcaptionbox{}{%
\begin{tikzpicture}[auto,node distance=3cm, thick, main node/.style={circle,draw,font=\sffamily\bfseries}]
\node[main node] (3) at (0,0) {};
\node[main node] (4) at (2,0) {};
\node[main node] (1) at (0,2) {};
\node[main node] (2) at (2,2) {};
\path (1) edge node{} (2);
\path (2) edge node{} (4);
\path (4) edge node{} (3);
\path (3) edge node{} (1);
\end{tikzpicture}
}
\end{subfigure}
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Properties of the entire figure
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\caption{Graphs and Labeling}
\label{fig:GraphsAndLabeling}
%
\medskip
\raggedright
\small
Description of the figure.
\end{figure}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment