Code snippets for figures:
- Standard figure
- Side-by-side figure (1×2)
- Side-by-side figure (2×2)
- Sideways-figure
- Wrap text around figure
- Side-by-side figures in beamer presentations
Standard figure
%Preamble
\usepackage{graphicx}
%Document
\begin{figure}[htbp]
\centering
\includegraphics[width=\linewidth]{figure.png}
\caption[short for lof]{long figure caption}
\label{fig:default}
\end{figure}
\ref{fig:default}
Side-by-side figure (1×2)
%Preamble
\usepackage[lofdepth]{subfig}
\usepackage{graphicx}
%Document
\begin{figure}[htbp] % h:here; t:top; b:bottom; p:page; default:ht
\centering
\subfloat[short for lof][long subfigure1 caption]{
\includegraphics[width=0.45\linewidth]{figure1.png}
\label{subfig:fig1}
}
\subfloat[short for lof][long subfigure2 caption]{
\includegraphics[width=0.45\linewidth]{figure2.png}
\label{subfig:fig2}
}
\caption[short for lof]{long figure caption}
\label{fig:fig1}
\end{figure}
\ref{fig:fig1} and \subref{subfig:fig1}
Side-by-side figure (2×2)
%Preamble
\usepackage[lofdepth,lotdepth]{subfig}
\usepackage{graphicx}
%Document
\begin{figure}[ht]
\centering
\subfloat[short for lof][long subfig1 caption]{
\includegraphics[width=0.45\linewidth]{figure1.png}
\label{subfig:fig1}
}
\subfloat[short for lof][long subfig2 caption]{
\includegraphics[width=0.45\linewidth]{figure2.png}
\label{subfig:fig2}
}
\subfloat[short for lof][long subfig3 caption]{
\includegraphics[width=0.45\linewidth]{figure3.png}
\label{subfig:fig3}
}
\subfloat[short for lof][long subfig4 caption]{
\includegraphics[width=0.45\linewidth]{figure4.png}
\label{subfig:fig4}
}
\caption[short for lof]{long figure caption}
\label{fig:fig1}
\end{figure}
\ref{fig:fig1} and \subref{subfig:fig1}
Sideways-figure
% Preamble
\usepackage{rotating}
% Document
\begin{sidewaysfigure}
\centering
\includegraphics{figure.png}
\caption{Sideways figure.}
\label{fig:swfig}
\end{sidewaysfigure}
Wrap text around figure
%Preamble
\usepackage{wrapfig, graphicx}
% Document
\begin{wrapfigure}{l}{0.5\textwidth} % l for left, r for right
\centering
\includegraphics[width=0.45\textwidth]{test}
\caption{Text wrapped around figure}
\label{fig:wrapfig}
\end{wrapfigure}
October 9th, 2012 at 12:41 pm
How can we make a figure of indifference curves, such as the following: http://www.google.gr/imgres?q=indifference+curves&um=1&hl=el&sa=N&biw=1280&bih=920&tbm=isch&tbnid=GaRBl0rVRm9ViM:&imgrefurl=http://www.cdc.gov/owcd/eet/cba/Fixed/3.html&docid=hzZjO5Idx_6w7M&imgurl=http://www.cdc.gov/owcd/eet/cba/images/CBA_budindif.gif&w=390&h=320&ei=Sxt0UMbhOMf34QT43IDoDw&zoom=1&iact=hc&vpx=836&vpy=289&dur=2119&hovh=203&hovw=248&tx=169&ty=53&sig=109547569904575331079&page=1&tbnh=136&tbnw=166&start=0&ndsp=30&ved=1t:429,r:10,s:0,i:99 ?
October 10th, 2012 at 3:37 am
Hi Giannis,
You could either use a free Math/Stats software such as R to create the graph and then add it to your document. Or, create the graph in LaTeX using TikZ/PGF (minimal introduction).
Cheers, Tom.
November 7th, 2012 at 9:57 am
Hey Tom once again,
How could I draw a hyperbola with the tikz package?
For example, I would like, how could I have the hyperbola: y=2000/(x+16.67).
Thanks in advance.
November 12th, 2012 at 1:13 am
Hi Giannis,
See here for how to plot a hyperbola using TikZ.
Best, Tom.
April 16th, 2013 at 3:43 pm
hi,
your 1×2 code produces subfigures with two brackets like ((a)) but it would be nicer to have (a)
thanks for nice code snippets
April 17th, 2013 at 2:31 am
Hi!
Thanks for your comment. I don’t get double parentheses using the standard LaTeX classes. What document-class do you use?
You can try to set the label format manually, through the caption package (page 6):
\usepackage{caption} \captionsetup[subfigure]{labelformat=parens, labelsep=none}