플래시 카드의 알고리즘

플래시 카드의 알고리즘

저는 알고리즘이 포함된 플래시 카드를 조합하려고 합니다. 다음 오류가 발생합니다.

! LaTeX Error: Not in outer par mode.

두 가지 질문이 있습니다.

  • 이 오류의 이유는 무엇입니까?
  • 어떻게 해결할 수 있나요?

다음 코드를 사용하면 오류가 발생했습니다.

\documentclass[grid,avery5371]{flashcards}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[ruled,vlined,rightnl,linesnumbered]{algorithm2e}

\geometry{headheight=12pt}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}

\cardbackstyle[\LARGE\bfseries]{plain}
\cardfrontstyle[\large]{headings}


\begin{document}

\begin{flashcard}[graph]{\textsc{dfs}}
  \begin{algorithm}
    \caption{DFS(G)}
    \For{u $\in$ G.V}{
      u.color $\gets$ \textsc{white} \\
      u.$\pi$ $\gets$ \textsc{nil} \\
    }
    \For{u $\in$ G.V}{
      \If{u.color = \textsc{white}}{
        \textsc{dfs-visit}(G, u)
      }
    }
  \end{algorithm}
\end{flashcard}

\end{document}

답변1

처음에는 텍스트가 너무 크다고 생각했는데 \cardheight두 개의 그리드 셀에 해당합니다.

\documentclass[grid,avery5371]{flashcards}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[ruled,vlined,rightnl,linesnumbered]{algorithm2e}

\geometry{headheight=12pt}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}

\cardbackstyle[\LARGE\bfseries]{plain}
\cardfrontstyle[\large]{headings}

\usepackage{graphicx}

\begin{document}

\begin{flashcard}[graph]{\textsc{dfs}}
  \scalebox{.8}{\begin{algorithm}[H]
    \caption{DFS(G)}
    \For{u $\in$ G.V}{
      u.color $\gets$ \textsc{white} \\
      u.$\pi$ $\gets$ \textsc{nil} \\
    }
    \For{u $\in$ G.V}{
      \If{u.color = \textsc{white}}{
        \textsc{dfs-visit}(G, u)
      }
    }
  \end{algorithm}}
\end{flashcard}

\end{document}

데모

관련 정보