1

I am formatting my thesis. During formatting, I am facing a problem as to how to split a long algorithm into two pages. Below is the dummy algo code. I have given all the packages used in the thesis so that any solution provided here will not contradict with any of the used packages. Originally I have a different document class - '\documentclass[12pt,openright,twoside]{ducs}'.

Before posting this question, I tried various solutions provided at the following links:

Divide algorithm inside If EndIf

Divide an algorithm on two pages

algorithm2e split over several pages

I tried to resolve it by using smaller font sizes but my problem still remains unsolved. I am totally confused now.

\documentclass{article}
\usepackage{ragged2e}
\usepackage{placeins}
\usepackage{enumitem}
%\usepackage[algo2e]{algorithm2e}
\usepackage{graphicx}
%\usepackage{subfigure}
\usepackage{multirow}
\usepackage{multicol}
%\usepackage{titlesec}
\setcounter{secnumdepth}{5}
\usepackage{longtable}
\usepackage{subfloat}
\usepackage{tabularx}
\usepackage{subfig}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{longtable}
\usepackage[lined,linesnumbered,ruled,resetcount,longend]{algorithm2e}
\usepackage{textgreek}
%\usepackage{enumerate}
\usepackage{caption}
\usepackage{csquotes}
\usepackage[T1]{fontenc}
\usepackage{scalerel}
\usepackage[utf8]{inputenc}
\usepackage[german,french,italian,welsh,greek,russian,portuguese,spanish,english]{babel}
\usepackage[tablename=Table]{caption}
\usepackage[dvipsnames,table,xcdraw]{xcolor}

\usepackage[UTF8]{ctex} \newcommand{\nextnr}{\stepcounter{AlgoLine}\ShowLn} \usepackage{epsfig} \usepackage{times} \usepackage{rotating} \usepackage{comment} %\usepackage{algorithm} %\usepackage{algpseudocode} %\algrenewcommand\textproc{} \usepackage{epsfig} \usepackage{amssymb} \usepackage[black-square]{QED} \usepackage{slashbox} \usepackage{caption} \captionsetup{font={small, singlespacing}} %\usepackage {subcaption} \usepackage{psfig} \usepackage{graphicx} \usepackage{amsmath} \usepackage{verbatim} \usepackage{psfig} \usepackage[a4paper,left=1.5in, right=1.1in, top=1.0in, bottom=.90in]{geometry} \usepackage[numbers]{natbib} \usepackage[T1]{fontenc} % important if your docs contain special characters \usepackage{epstopdf}% \usepackage{units} % for solidus fractions % \usepackage{array,booktabs,ragged2e} \usepackage{multirow} \usepackage{pdflscape} \usepackage{placeins} \usepackage{float, caption} \floatstyle{boxed} \usepackage{framed} \usepackage[framemethod=tikz]{mdframed}

\mdfdefinestyle{myFigureBoxStyle}{tikzsetting={draw=black, line width=1pt}}% \makeatletter \newcommand\fs@myRoundBox{\def@fs@cfont{\bfseries}\let@fs@capt\floatc@plain \def@fs@pre{\begin{mdframed}[style=myFigureBoxStyle]}% \def@fs@mid{\vspace{\abovecaptionskip}}% \def@fs@post{\end{mdframed}}\let@fs@iftopcapt\iffalse} \makeatother \usepackage{footnote}

\usepackage{threeparttable} \usepackage{array} \newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}} \newcolumntype{L}{>{\centering\arraybackslash}m{6cm}} \newcolumntype{L}{>{\centering\arraybackslash}m{6cm}} \newcolumntype{C}{>{\centering\arraybackslash}m{3cm}}

\usepackage{longtable} \makesavenoteenv{tabular} \usepackage{color} %May be necessary if you want to color links \usepackage[breaklinks=true]{hyperref} \hypersetup{ linktoc=all, %set to all if you want both sections and subsections linked }

\setcounter{secnumdepth}{4} \setcounter{tocdepth}{2}

%\floatname {algorithm}{Procedure} %\renewcommand {\algorithmicrequire} {\textbf{Input:}} %\renewcommand {\algorithmicensure} {\textbf{Output:}} \newtheorem{defn}{Definition} \newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} \newfont{\mycrnotice}{ptmr8t at 7pt} \newfont{\myconfname}{ptmri8t at 7pt} \let\crnotice\mycrnotice% \let\confname\myconfname% \graphicspath{ {images/} }

\newtheorem{theorem}{Theorem}[chapter] \newtheorem{assertion}[theorem]{Assertion} \newtheorem{claim}[theorem]{Claim} \newtheorem{conjecture}[theorem]{Conjecture} \newtheorem{corollary}[theorem]{Corollary} \newtheorem{example}[theorem]{Example} \newtheorem{figger}[theorem]{Figure} \newtheorem{lemma}[theorem]{Lemma} \newtheorem{prop}[theorem]{Proposition} \newtheorem{remark}[theorem]{Remark} \newtheorem{definition}{Definition}[section] \renewcommand {\nomenclature} {Notations} \renewcommand\floatpagefraction{.9} \renewcommand\topfraction{.9} \renewcommand\bottomfraction{.9} \renewcommand\textfraction{.1} \setcounter{totalnumber}{50} \setcounter{topnumber}{50} \setcounter{bottomnumber}{50}

\hyphenation{semi-blind Bi-directional} \usepackage{url} \urlstyle{same} \listfiles \begin{document} \begin{algorithm}[H]

\SetKwInOut{KwIn}{Input} \SetKwInOut{KwOut}{Output} \KwIn{Text Input.} \KwOut{Text Output.}

\nextnr \For{each condition1 }{ Obtain TR } \nextnr \For{each condition2 }{ \nextnr Obtain TR corresponding to the code. \end{algorithm} \begin{algorithm}[H] \nextnr \uIf{ condition3 }{ goto step 11. }

\Else{ \uIf{condition4}{ go to step 7. } \Else{ Find the compound score. Append TR. %\end{enumerate} } } \nextnr \uIf{ condition5}{ go to step 8. } \Else{ go to step 9. } \nextnr Obtain TR. \

\nextnr Find the sum. \ \nextnr \uIf{condition 6 }{ Find the score, \textit{score}.\ } \Else { Find the compound score.\ }

\nextnr \uIf{condition7}{ Obtain TR. } \Else{ Obtain TR1 } Go to step 12. \ \nextnr Replace the first TR \

\nextnr Replace code with the TR.

}

\caption{Algo Demo}

\end{algorithm} \end{document}

  • 1
    It might help to use more functional and structured programming. Separate meaningful parts of your method into a separate functions, place them into separate algorithm environments, make a call in your main algorithm. – Oleg Lobachev Sep 13 '20 at 21:33
  • As per the actual algo, it's not feasible to use modules. – Tripti Agrawal Sep 14 '20 at 03:40
  • I have observed that by reducing the vertical spacing in between the lines can solve my problem. – Tripti Agrawal Sep 14 '20 at 19:28
  • However, the use of '\captionsetup{font={small, singlespacing}}' and \useackage{setspace} in the preamble are contradicting, hence getting error. I need help in overriding spacing in only one algorithm. – Tripti Agrawal Sep 15 '20 at 11:41

0 Answers0