
我正在嘗試將帶有演算法的閃存卡放在一起。我收到以下錯誤:
! 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}