编译下面的 MWE 时,我收到错误“未定义控制序列 \hline”和“未定义控制序列 \hdashline”。该问题是由eqparbox
包,因为代码在没有它的情况下也能很好地编译 - 除了在算法部分对齐注释(这正是我使用的原因eqparbox
)。单独编译表和算法(见下文)不会出现任何错误。
\documentclass[12pt]{report}
\usepackage{arydshln}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{trimspaces}
\usepackage{eqparbox}
\renewcommand{\algorithmiccomment}[1]{\hfill\eqparbox{COMMENT}{\% #1}}
\begin{document}
\begin{table}[htbp]
\caption{A simple table with horizontal and dashed horizontal lines.}
\label{tab:Simple}
\begin{center}
\begin{tabular}{l|c|c|c|c|c|c|}
& \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} & \textbf{E} & \textbf{F} \\
\hline
\textbf{A} & 0 & 1 & 0 & 0 & 1 & 1 \\
\hdashline
\textbf{B} & 1 & 0 & 1 & 0 & 1 & 0 \\
\hdashline
\textbf{C} & 0 & 1 & 0 & 1 & 0 & 0 \\
\hdashline
\textbf{D} & 0 & 0 & 1 & 0 & 1 & 0 \\
\hdashline
\textbf{E} & 1 & 1 & 0 & 1 & 0 & 0 \\
\hdashline
\textbf{F} & 1 & 0 & 0 & 0 & 0 & 0 \\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{algorithm}
\caption{Euclid's algorithm}\label{alg:Euclid}
\begin{algorithmic}[1]
\Procedure{Euclid}{$a,b$}
\Comment{The g.c.d. of a and b}
\State $r \gets a \bmod b$
\While{$r \neq 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{document}
关于如何解决此问题的任何想法,以便表格看起来像:
\documentclass[12pt]{report}
\usepackage{arydshln}
\begin{document}
\begin{table}[htbp]
\caption{A simple table with horizontal and dashed horizontal lines.}
\label{tab:Simple}
\begin{center}
\begin{tabular}{l|c|c|c|c|c|c|}
& \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} & \textbf{E} & \textbf{F} \\
\hline
\textbf{A} & 0 & 1 & 0 & 0 & 1 & 1 \\
\hdashline
\textbf{B} & 1 & 0 & 1 & 0 & 1 & 0 \\
\hdashline
\textbf{C} & 0 & 1 & 0 & 1 & 0 & 0 \\
\hdashline
\textbf{D} & 0 & 0 & 1 & 0 & 1 & 0 \\
\hdashline
\textbf{E} & 1 & 1 & 0 & 1 & 0 & 0 \\
\hdashline
\textbf{F} & 1 & 0 & 0 & 0 & 0 & 0 \\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}
算法如下:
\documentclass[12pt]{report}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{trimspaces}
\usepackage{eqparbox}
\renewcommand{\algorithmiccomment}[1]{\hfill\eqparbox{COMMENT}{\% #1}}
\begin{document}
\begin{algorithm}
\caption{Euclid's algorithm}\label{alg:Euclid}
\begin{algorithmic}[1]
\Procedure{Euclid}{$a,b$}
\Comment{The g.c.d. of a and b}
\State $r \gets a \bmod b$
\While{$r \neq 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{document}
答案1
只需调整加载顺序,使其eqparbox
位于之前arydshln
:
\documentclass[12pt]{report}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{trimspaces}
\usepackage{eqparbox}
\usepackage{arydshln}
\renewcommand{\algorithmiccomment}[1]{\hfill\eqparbox{COMMENT}{\% #1}}
\begin{document}
\begin{table}[htbp]
\caption{A simple table with horizontal and dashed horizontal lines.}
\label{tab:Simple}
\begin{center}
\begin{tabular}{l|c|c|c|c|c|c|}
& \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} & \textbf{E} & \textbf{F} \\
\hline
\textbf{A} & 0 & 1 & 0 & 0 & 1 & 1 \\
\hdashline
\textbf{B} & 1 & 0 & 1 & 0 & 1 & 0 \\
\hdashline
\textbf{C} & 0 & 1 & 0 & 1 & 0 & 0 \\
\hdashline
\textbf{D} & 0 & 0 & 1 & 0 & 1 & 0 \\
\hdashline
\textbf{E} & 1 & 1 & 0 & 1 & 0 & 0 \\
\hdashline
\textbf{F} & 1 & 0 & 0 & 0 & 0 & 0 \\
\hline
\end{tabular}
\end{center}
\end{table}
\begin{algorithm}
\caption{Euclid's algorithm}\label{alg:Euclid}
\begin{algorithmic}[1]
\Procedure{Euclid}{$a,b$}
\Comment{The g.c.d.\ of $a$ and $b$}
\State $r \gets a \bmod b$
\While{$r \neq 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 g.c.d.\ is $b$}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
请注意,我还修复了您特定评论中的标记,添加了数学模式并修复了缩写点后的间距。