# How to give floats/figures titles?

Below is an excerpt from my thesis, showing a figure with a caption.

I'd like to give the figure a title too, that is, a few words written above the figure.

Can I do that in latex? If so, how?

\begin{figure}
\includegraphics[width=\linewidth]{./graphics/chapter6/mouse.pdf}
\caption{Blablabla}
\label{fig:length_eight_mouse}
\end{figure}

-
Did you create the plot with matplotlib? Then you could also add a title there, though the font wouldn't match the document font. –  Torbjørn T. Aug 14 '13 at 11:42
Yes, that's why I did not include one there. The fonts did not match and it all became so tacky. –  The Unfun Cat Aug 14 '13 at 11:44
The fonts don't match on your axis scales either (and presumably your axis labels) - your are labelling your axes I assume? I've just been testing an alternative approach for my thesis - see my answer below. –  Chris H Aug 15 '13 at 11:51

The {figure} environment isn't limited to contain only figures etc. You can add anything so just type in your title above the figure.

\begin{figure}
\centering
\includegraphics[scale=0.3]{example-image}
\end{figure}


You can define a new command like \figuretitle to make the formatting and spacing consistent.

\newcommand*{\figuretitle}[1]{%
{\centering%   <--------  will only affect the title because of the grouping (by the
\textbf{#1}%              braces before \centering and behind \medskip). If you remove
\par\medskip}%            these braces the whole body of a {figure} env will be centered.
}


Looks the same as above, but can be used as

\begin{figure}
\centering
\includegraphics[scale=0.3]{example-image}
\end{figure}


Or you can use the \caption above the figure. In this case you may use the caption package to adjust the spacing.

\documentclass{article}

\usepackage{graphicx}

\usepackage{caption}
\captionsetup[figure]{
position=above,
}

\begin{document}
\begin{figure}
\centering
\includegraphics[scale=0.3]{example-image}
\end{figure}
\end{document}

-
Thanks. Ps. for other newbs: \newcommands should be inserted in your config-file to get it to work in every chapter. In my case this is classicthesis-config.tex. –  The Unfun Cat Aug 14 '13 at 11:54
This is not wrong but neither correct ;-) You can place the definition anywhere in sour document and use it frome there on. It is common sense to put definition in the preamble, i.e. the part before \begin{document}, and the definition is scoped by a group, e.g. An environment ... –  Tobi Aug 14 '13 at 13:06
Thanks. Right. Classicthesis has even included a space in the preamble for this. Ps. I guess the \centering does not need to be included when you use the \figuretitle? –  The Unfun Cat Aug 15 '13 at 7:03
@TheUnfunCat: Yes the \centering is kind of redundant in this case, but I used a group, i.e. a pair of braces {}, so \centering will only affect the title and not the image. If you want to center all images I’d do it globally, see tex.stackexchange.com/q/6033/4918. –  Tobi Aug 15 '13 at 10:47

An alternative method is to output from Matplotlib as .svg, with or without a title then read in to Inkscape. You can save from Inkscape as .pdf+.tex (or .eps+.tex I think), where the .pdf(.eps) contains the graphics, and the .tex overlays the text, in your current document font. All this can be done from the command line - Inkscape supports that.

Setting up matplotlib to output text as text

Adjusting sizing of figure and text

-

You could try making the matplotlib text look like LaTeX:

%matplotlib inline
from matplotlib import pyplot as plt

# This is the first important line:
from matplotlib import rcParams

plt.plot([1, 2, 3, 4],
[2, 4, 6, 8])

# These are the second and third important lines:
plt.rc('text', usetex=True)
plt.rc('font', family='serif')

# Change the fontsize to match your document.
plt.xlabel("This is a cool label.", fontsize=12)
plt.ylabel("This is another cool label.", fontsize=12)
plt.savefig("image.pdf", dpi=200)
`

-
I found these two web pages very useful to produce the plots of my thesis with Matplotlib: wiki.scipy.org/Cookbook/Matplotlib/LaTeX_Examples and wiki.scipy.org/Cookbook/Matplotlib/UsingTex . However I would not do it again; instead I would let LaTeX produce the plots itself (see ticz package for instance). Advantages: (1) actually looks like LaTeX; (2) fix typos, resize and restyle without having to rerun your 4-years-old python code and (3) no need to deal with Matplotlib's maddening API and documentation. –  Niriel May 22 at 11:04