3

I have something like this:

\usepackage{algorithm}
\usepackage{algpseudocode}

...
\begin{document}
\begin{algorithm}[H]
\begin{algorithmic}[1]
\Function {function}{a}
\State a = a + 1
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{document}

I'm using [H] because I want to set the position of my code. But after doing that a space for caption appears and I don't want it and now there are to horizontal lines beafore my code. You can see what I mean in this picture: enter image description here

How can I remove one of those lines?

Thanks!

2
  • Welcome to TeX.SX! Why do you use the float if you force it in bad style to be where it is in code and you do not want to caption it? Just remove your algorithm environment. – TeXnician Apr 1 '17 at 16:32
  • Because I want it to be between lines. Sorry if this is a bad practice but it's my first time using these packages. @TeXnician – Néstor Apr 1 '17 at 16:38
3

Define your own version:

\documentclass{article}
\usepackage{algpseudocode}

\usepackage{lipsum} % for the example

\newenvironment{algo}
 {\par\addvspace{\topsep}
  \centering
  \begin{minipage}{\linewidth}
  \hrule\kern2pt}
 {\par\kern2pt\hrule
  \end{minipage}
  \par\addvspace{\topsep}}

\begin{document}

\lipsum[2]

\begin{algo}
\begin{algorithmic}[1]
\Function {function}{a}
\State a = a + 1
\EndFunction
\end{algorithmic}
\end{algo}

\lipsum[3]

\end{document}

enter image description here

0

In order to achieve this, you need to define a new \floatstyle. Here's one such option (I called it nocaptionruled):

enter image description here

\documentclass{article}

\usepackage{algorithm,algpseudocode}

\makeatletter
\newcommand\fs@nocaptionruled{%\def\@fs@cfont{\bfseries}%
  \let\@fs@capt\relax%\floatc@ruled
  \def\@fs@pre{}%{\hrule height.8pt depth0pt \kern2pt}%
  \def\@fs@post{\kern2pt\hrule\relax}%
  \def\@fs@mid{\kern2pt\hrule\kern2pt}%
  \let\@fs@iftopcapt\iftrue}
\makeatother

\begin{document}

\begin{algorithm}[H]
  \begin{algorithmic}[1]
    \Function{function}{a}
      \State a = a + 1
    \EndFunction
  \end{algorithmic}
\end{algorithm}

\floatstyle{nocaptionruled}
\restylefloat{algorithm}

\begin{algorithm}[H]
  \begin{algorithmic}[1]
    \Function{function}{a}
      \State a = a + 1
    \EndFunction
  \end{algorithmic}
\end{algorithm}

\end{document}
3
  • This works, but if after my code i use another code without using [H] the only one line is missed, any solution? – Néstor Apr 1 '17 at 16:44
  • @n23: So you have two algorithmic environments in a single algorithm? – Werner Apr 1 '17 at 17:18
  • No, nevermind, @egreg solve it! – Néstor Apr 1 '17 at 17:24

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.