[Tex/LaTex] How to fix caption in moderncv

captionsfloatsminipagemoderncv

I'm using moderncv and I want to add a caption to an inserted graphic. I'm currently using this code

\begin{minipage}{.5\textwidth}
  \centering
  \includegraphics[width=0.5\textwidth]{fixed_button_settings.png}
  \captionof{figure}{Some figure}           
\end{minipage}

and this is the result

fixed_button_settings.png

For further notice, this line of code

\captionof{figure}{Some figure} 

results in an error: Package caption Error: No float type 'figure' defined.

I have added this in the main.tex preamble

\usepackage{float}
\usepackage{caption}

What should I do to make the caption appear as: "Figur 1: Some figure"? ("Figur" is not a typo, it's Swedish.)

Best Answer

Your problem is that class moderncv has no floating environment figure implemented. So you have two possibilities:

  1. copy all the code needed for figure into an own local new class mymoderncv.cls or
  2. do not use figure and make it by your own. You can use minipage, and write the heading by your own, because in a cv you need no list of figures, I guess?

A solution for point 2 could be (I used the image from package mwe, that must be installed, but must not be loaded):

\documentclass[%
  11pt
 ,a4paper
 ,sans
]{moderncv}

\moderncvstyle{classic}
\moderncvcolor{blue}

\usepackage[scale=0.75]{geometry}
%\usepackage[english,ngerman]{babel}

% Personal Data
\firstname{John}
\familyname{Doe}
\title{Resume title}
\address{street and number}{postcode city}{country}\mobile{+1~(234)~567~890}
\phone{+2~(345)~678~901}
\fax{+3~(456)~789~012}
\email{john@johndoe.com}
\homepage{www.johndoe.com}
\extrainfo{additional information}
\quote{Some quote from a well known person}

\begin{document}

\makecvtitle

\section{Education}
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}

\section{Master thesis}
\cvitem{title}{\emph{Title}}
\cvitem{supervisors}{Supervisors}
\cvitem{description}{Short thesis abstract}

\begin{minipage}{\textwidth}
  \centering
  \includegraphics[width=0.5\textwidth]{example-image-a} \\
  Figure 1: heading of figure.
\end{minipage}

\end{document}

with the result:

enter image description here

Related Question