Advertisement
TheRolf

MWE for algsubstates

Jul 7th, 2020
1,549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 2.00 KB | None | 0 0
  1. \documentclass[11pt,a4paper]{article}
  2. \usepackage{fullpage}
  3.  
  4. \usepackage[english]{babel}
  5. \usepackage{color}
  6. \usepackage{hyperref}
  7. \usepackage[nameinlink]{cleveref}
  8.  
  9. \hypersetup{colorlinks=true, linkcolor=blue}
  10. \usepackage{algorithm}
  11. \usepackage[noend]{algpseudocode}
  12.  
  13. \newcounter{algsubstate}
  14. \makeatletter
  15. \renewcommand{\thealgsubstate}{\arabic{ALG@line}.\alph{algsubstate}}
  16. \makeatother
  17. \newenvironment{algsubstates}
  18.  {\setcounter{algsubstate}{0}%
  19.    \renewcommand{\State}{%
  20.      \refstepcounter{algsubstate}%
  21.      \Statex {\footnotesize\alph{algsubstate}:}\space}}
  22.  {}
  23.  
  24. \crefname{line}{step}{steps}
  25. \crefname{algsubstate}{step}{steps}
  26.  
  27. \begin{document}
  28.  
  29. \begin{algorithm}[h!]
  30. \caption{Algorithm A}\label{a}
  31. \begin{algorithmic}[1]
  32.  \State First operation \label{a_first}
  33.  \State Second operation \label{a_second}
  34.  \begin{algsubstates}
  35.    \State Part a of second \label{a_second_a}
  36.    \State Part b of second \label{a_second_b}
  37.  \end{algsubstates}
  38.  \State Third operation \label{a_third}
  39. \end{algorithmic}
  40. \end{algorithm}
  41.  
  42. \newpage
  43.  
  44. \begin{algorithm}[h!]
  45. \caption{Algorithm B}\label{b}
  46. \begin{algorithmic}[1]
  47.  \State First operation \label{b_first}
  48.  \State Second operation \label{b_second}
  49.  \begin{algsubstates}
  50.    \State Part a of second \label{b_second_a}
  51.    \State Part b of second \label{b_second_b}
  52.  \end{algsubstates}
  53.  \State Third operation \label{b_third}
  54. \end{algorithmic}
  55. \end{algorithm}
  56.  
  57. \newpage
  58.  
  59. \subsubsection*{Cleveref}
  60. \noindent
  61. Algorithm A is \Cref{a}: \Cref{a_first,a_second}. Also \Cref{a_second_a,a_second_b,a_third} \\
  62. Algorithm B is \Cref{b}: \Cref{b_first,b_second}. Also \Cref{b_second_a,b_second_b,b_third}
  63.  
  64. \subsubsection*{Normal}
  65. \noindent
  66. Algorithm A is Algorithm \ref{a}: Steps \ref{a_first} and \ref{a_second}. Also Steps \ref{a_second_a}, \ref{a_second_b} and \ref{a_third}. \\
  67. Algorithm B is Algorithm \ref{b}: Steps \ref{b_first} and \ref{b_second}. Also Steps \ref{b_second_a}, \ref{b_second_b} and \ref{b_third}.
  68.  
  69. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement