Math & Sciencemissplaced text in a long algorithm

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

missplaced text in a long algorithm

Post by NELLLY »

Hello, I have a long algorithm to put in my report. There is a text before the beginning of it. I used the following code

Code: Select all

\documentclass{report}
\usepackage{minitoc}
\usepackage{nomencl}
\usepackage{glossaries}
\usepackage[pdftex]{graphicx}       % to insert PostScript figures
\usepackage{rotating}
\usepackage{footnote}       % for sideways tables/figures
\usepackage{siunitx,amsmath,geometry}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage[chapter]{algorithm}
\usepackage{algorithmicx,tabularx}
%\usepackage{algorithmicx,tabularx}
\usepackage{rotating,multirow}
\usepackage[format=hang]{caption}
\usepackage{fancybox}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{geometry}
\usepackage{float,array}
\usepackage{algcompatible,enumitem}
\usepackage[compatible]{algpseudocode}
\usepackage{xcolor,colortbl,threeparttable}
\usepackage{filecontents,pgfplotstable,mathtools}
%\usepackage[round]{natbib}
\floatstyle{boxed}
\renewcommand{\baselinestretch}{1.5}
\setlength{\evensidemargin}{3.5cm}
\setlength{\textwidth}{6in}%6 inc
\setlength{\textheight}{8.9in}
\setlength{\topmargin}{-0.6in}
\setlength{\topmargin}{-0.2in}
\setlength{\headsep}{.4in}
\setlength{\footnotesep}{.2in}
\setlength{\parindent}{0.5cm}
%\nofiles
\hyphenpenalty 10000
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\let\OldStatex\Statex
\renewcommand{\Statex}[1][6]{%
  \setlength\@tempdima{\algorithmicindent}%
  \OldStatex\hskip\dimexpr#1\@tempdima\relax}
\makeatother
%%%%%%%%%Customization of my algorithms%%%%%%%%%
%%%%%%%%%%%%%Text circled numbers
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{\node[shape=circle, draw, inner sep=1pt](char){#1};}}
\begin{document}
\algrenewcommand{\alglinenumber}[1]{\scriptsize\circled{#1}}
\renewcommand{\algorithmicforall}{\textbf{For each}}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\subsection*{Proposed algorithm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\lipsum[1]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{algorithm}[H]
\caption{Determination of the optimal design parameters of the Bayes-n $np$ control chart}
\begin{algorithmic}[1]
\Require The value of ...
\Ensure The ...
\State...
\State .....  
\State .... 
\State ...
\State ....
\ForAll{value of ....}
\State ...
\State ...
\If{...}
\State ...
\ElsIf{...}
\State ...
\ForAll{...}
\State ...
\State ...
\State ...
\EndFor
\algstore{NAME}
\end{algorithmic}
\end{algorithm}
\begin{algorithm}
\begin{algorithmic}[1]%[1]
\algrestore{NAME}
\State...
\ForAll{...}
\ForAll{...}
\ForAll{...}
\State ...

\While{...}
\State ...
\State ...
\State ...
\State ...
\State ...
\State ...
\EndWhile
\State ...
\EndFor
\EndFor
\EndFor
\Else
\State...
\State ...
\State ...
\ForAll{...}
\ForAll{...}
\ForAll{...}
\State ...
\While{...}
\State...
\State ...
\State ...
\State ...
\State...
\State ...


\algstore{NAME}
\end{algorithmic}
\end{algorithm}
\begin{algorithm}
\begin{algorithmic}[1]
\algrestore{NAME}
\EndWhile
\EndFor
\EndFor
\EndFor 
\State ...
\EndIf 
\EndFor
\State ...
\State ...
\end{algorithmic}
\end{algorithm}
\lipsum[2]
\end{document}
By doing so, I got some text betwwen the different parts of the algorithms. I tried to use \begin{algorithm}[H] in the two parts break of the algorithm, there is no text betwwen them however I got an extra horizontal line at the beginning of them.
Is there a solution?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: missplaced text in a long algorithm

Post by Johannes_B »

Better place huge algorithms like that into the appendix.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply