LaTeX forum ⇒ Math & Sciencemissplaced text in a long algorithm

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

missplaced text in a long algorithm

Postby NELLLY » Sat Mar 05, 2016 5:50 pm

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
  1. \documentclass{report}
  2. \usepackage{minitoc}
  3. \usepackage{nomencl}
  4. \usepackage{glossaries}
  5. \usepackage[pdftex]{graphicx} % to insert PostScript figures
  6. \usepackage{rotating}
  7. \usepackage{footnote} % for sideways tables/figures
  8. \usepackage{siunitx,amsmath,geometry}
  9. \usepackage{amssymb}
  10. \usepackage{booktabs}
  11. \usepackage[chapter]{algorithm}
  12. \usepackage{algorithmicx,tabularx}
  13. %\usepackage{algorithmicx,tabularx}
  14. \usepackage{rotating,multirow}
  15. \usepackage[format=hang]{caption}
  16. \usepackage{fancybox}
  17. \usepackage{fancyhdr}
  18. \usepackage{tikz}
  19. \usepackage{lipsum}
  20. \usepackage{geometry}
  21. \usepackage{float,array}
  22. \usepackage{algcompatible,enumitem}
  23. \usepackage[compatible]{algpseudocode}
  24. \usepackage{xcolor,colortbl,threeparttable}
  25. \usepackage{filecontents,pgfplotstable,mathtools}
  26. %\usepackage[round]{natbib}
  27. \floatstyle{boxed}
  28. \renewcommand{\baselinestretch}{1.5}
  29. \setlength{\evensidemargin}{3.5cm}
  30. \setlength{\textwidth}{6in}%6 inc
  31. \setlength{\textheight}{8.9in}
  32. \setlength{\topmargin}{-0.6in}
  33. \setlength{\topmargin}{-0.2in}
  34. \setlength{\headsep}{.4in}
  35. \setlength{\footnotesep}{.2in}
  36. \setlength{\parindent}{0.5cm}
  37. %\nofiles
  38. \hyphenpenalty 10000
  39. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  40. \makeatletter
  41. \let\OldStatex\Statex
  42. \renewcommand{\Statex}[1][6]{%
  43. \setlength\@tempdima{\algorithmicindent}%
  44. \OldStatex\hskip\dimexpr#1\@tempdima\relax}
  45. \makeatother
  46. %%%%%%%%%Customization of my algorithms%%%%%%%%%
  47. %%%%%%%%%%%%%Text circled numbers
  48. \newcommand*\circled[1]{\tikz[baseline=(char.base)]{\node[shape=circle, draw, inner sep=1pt](char){#1};}}
  49. \begin{document}
  50. \algrenewcommand{\alglinenumber}[1]{\scriptsize\circled{#1}}
  51. \renewcommand{\algorithmicforall}{\textbf{For each}}
  52. \renewcommand{\algorithmicrequire}{\textbf{Input:}}
  53. \renewcommand{\algorithmicensure}{\textbf{Output:}}
  54. \subsection*{Proposed algorithm}
  55. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  56. \lipsum[1]
  57. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  58. \begin{algorithm}[H]
  59. \caption{Determination of the optimal design parameters of the Bayes-n $np$ control chart}
  60. \begin{algorithmic}[1]
  61. \Require The value of ...
  62. \Ensure The ...
  63. \State...
  64. \State .....
  65. \State ....
  66. \State ...
  67. \State ....
  68. \ForAll{value of ....}
  69. \State ...
  70. \State ...
  71. \If{...}
  72. \State ...
  73. \ElsIf{...}
  74. \State ...
  75. \ForAll{...}
  76. \State ...
  77. \State ...
  78. \State ...
  79. \EndFor
  80. \algstore{NAME}
  81. \end{algorithmic}
  82. \end{algorithm}
  83. \begin{algorithm}
  84. \begin{algorithmic}[1]%[1]
  85. \algrestore{NAME}
  86. \State...
  87. \ForAll{...}
  88. \ForAll{...}
  89. \ForAll{...}
  90. \State ...
  91.  
  92. \While{...}
  93. \State ...
  94. \State ...
  95. \State ...
  96. \State ...
  97. \State ...
  98. \State ...
  99. \EndWhile
  100. \State ...
  101. \EndFor
  102. \EndFor
  103. \EndFor
  104. \Else
  105. \State...
  106. \State ...
  107. \State ...
  108. \ForAll{...}
  109. \ForAll{...}
  110. \ForAll{...}
  111. \State ...
  112. \While{...}
  113. \State...
  114. \State ...
  115. \State ...
  116. \State ...
  117. \State...
  118. \State ...
  119.  
  120.  
  121. \algstore{NAME}
  122. \end{algorithmic}
  123. \end{algorithm}
  124. \begin{algorithm}
  125. \begin{algorithmic}[1]
  126. \algrestore{NAME}
  127. \EndWhile
  128. \EndFor
  129. \EndFor
  130. \EndFor
  131. \State ...
  132. \EndIf
  133. \EndFor
  134. \State ...
  135. \State ...
  136. \end{algorithmic}
  137. \end{algorithm}
  138. \lipsum[2]
  139. \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?

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

Postby Johannes_B » Mon Mar 07, 2016 9:12 am

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.


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 3 guests