1

I am trying to create a standalone subfile in which I want to add some algorithms.

The document is compiled right when I am using the \documentclass[9pt]{article} in the preamble. But the following error occurred when I change it into

\documentclass[float=false, crop=false]{standalone}
\usepackage[subpreambles=true]{standalone}`

The error output:

ERROR: Extra }, or forgotten \endgroup.
--- TeX said ---
\@endfloatbox ...pagefalse \outer@nobreak \egroup                                                          \color@endbox 
l.28 \end{algorithm}

--- HELP ---
From the .log file...

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

Whole code:

%\documentclass[float=false, crop=false]{standalone}
%\usepackage[subpreambles=true]{standalone}

\documentclass[9pt]{article} 
\usepackage{import}
\usepackage{booktabs}
\usepackage{siunitx}

\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\begin{document}

\begin{center}
\begin{algorithm}{}
    \caption{Euclid’s algorithm}
    \label{euclid}
    \begin{algorithmic}[1] % The number tells where the line numbering should start
        \Procedure{Euclid}{$a,b$} \Comment{The g.c.d. of a and b}
            \State $r\gets a \bmod b$
            \While{$r\not=0$} \Comment{We have the answer if r is 0}
                \State $a \gets b$
                \State $b \gets r$
                \State $r \gets a \bmod b$
            \EndWhile\label{euclidendwhile}
            \State \textbf{return} $b$\Comment{The gcd is b}
        \EndProcedure
    \end{algorithmic}
\end{algorithm}
\end{center}
\end{document}

Edit

Problem solved by replacing the floating boolean value in documentclass \documentclass[float=true, crop=false]{standalone} I am not sure why.

1

Since standalone does not have a predefined width, normal text breaking doesn't apply. You will need to put everything inside a minipage or use the varwidth package. Other things are undefined or just not a good idea in standalone.

\documentclass[varwidth]{standalone}
\usepackage[noend]{algpseudocode}
\begin{document}
    \begin{algorithmic}[1] % The number tells where the line numbering should start
        \Procedure{Euclid}{$a,b$} \Comment{The g.c.d. of a and b}
            \State $r\gets a \bmod b$
            \While{$r\not=0$} \Comment{We have the answer if r is 0}
                \State $a \gets b$
                \State $b \gets r$
                \State $r \gets a \bmod b$
            \EndWhile%\label{euclidendwhile}% won't work
            \State \textbf{return} $b$\Comment{The gcd is b}
        \EndProcedure
    \end{algorithmic}
\end{document}

And this is how you should use it in a document. BTW, don't put floats inside a center environment.

\documentclass[9pt]{article} 
\usepackage{import}
\usepackage{booktabs}
\usepackage{siunitx}

\usepackage{algorithm}
%\usepackage[noend]{algpseudocode}% not needed
\usepackage{graphicx}
\begin{document}

\begin{algorithm}
    \caption{Euclid’s algorithm}
    \label{euclid}
    \includegraphics{test5}% insert your filensmae here
\end{algorithm}
\end{document}

demo

0

Problem solved by replacing the floating boolean value in documentclass \documentclass[float=true, crop=false]{standalone}

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.