0

I am writing an algorithm in the figure environment, and when I write caption, it does not appear decently. Rather, it appears too close to the textbox.

Here is a MWE

\documentclass[10pt,emptycopyrightspace]{ewsn-proc}
\usepackage{amsmath,balance,amssymb,amsfonts,complexity,filecontents,graphicx,pgfplots,textcomp,tikz,tikz-3dplot}
\usepackage[most]{tcolorbox}
\usepackage[noend]{algpseudocode}
\usepackage{algorithm}
\usepackage[sort,nocompress]{cite}
\begin{document}
    \begin{figure}[htbp]
        \fbox{\begin{minipage}{\columnwidth}
                \textsc{SomeAlgorithm}
                \begin{algorithmic}[1]

                    \State Do this
                    \State Do that
                    \If{You cannot do this or that}
                    \State Do something else
                    \EndIf
                    \While{You are not successful}
                    \State Work hard
                    \EndWhile
        \end{algorithmic}  \end{minipage}}

        \caption{Some algorithm}
    \end{figure}
\end{document}

And this is the output: enter image description here

The caption is too close to the border of the figure. I tried to give some space with \vspace{...} but it does not work.

How can write captions such that they are a bit far away from the figure?

  • in article class it compiles ok without this problem. This means that your class or your class options causes this problem. Please provide a way to access somewhere your class. (Also edit your post to add the first backslash above the code at your documentcalss command) – koleygr Sep 7 '17 at 22:11
  • 1
    Look into the caption - this lets you customise basically everything of a caption. – user36296 Sep 7 '17 at 22:13
2

Just add the caption package, which sets more decent spacing between caption and float. This being said, I don't see why you don't use the algorithm environment, with style boxed. You'll also have a separate numbering for algorithms. As I don't have your class installed I use article with option twocolumn:

\documentclass[10pt, twocolumn]{article}%,emptycopyrightspace]{ewsn-proc}%
\usepackage{amsmath, amssymb, amsfonts, balance, filecontents, graphicx, complexity, pgfplots, textcomp, tikz, tikz-3dplot}%,
\usepackage[most]{tcolorbox}
\usepackage[noend]{algpseudocode}
\usepackage[boxed]{algorithm}
\usepackage{caption}
\captionsetup[boxed]{skip=6pt}
\usepackage{lipsum}
\usepackage[sort,nocompress]{cite}

\begin{document}

\lipsum[11]
 \begin{figure}[htbp]
 \fbox{\begin{minipage}{\columnwidth}
 \textsc{SomeAlgorithm}
 \begin{algorithmic}[1]

 \State Do this
 \State Do that
 \If{You cannot do this or that}
 \State Do something else
 \EndIf
 \While{You are not successful}
 \State Work hard
 \EndWhile
 \end{algorithmic} \end{minipage}}

 \caption{Some algorithm}
 \end{figure}
\lipsum[11]
    \begin{algorithm}[htbp]%
    \textsc{Some Algorithm}
                \begin{algorithmic}%[1]
                    \State Do this
                    \State Do that
                    \If{You cannot do this or that}
                    \State Do something else
                    \EndIf
                    \While{You are not successful}
                    \State Work hard
                    \EndWhile
        \end{algorithmic}
    \caption{Some algorithm}
    \end{algorithm}
\lipsum[6-10]

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.