3

When compiling the MWE below, I get presented with the errors "Undefined control sequence \hline" and "Undefined control sequence \hdashline". The problem is caused by the eqparbox package, as code compiles fine without it - with the exception of aligning the comments in the algorithm section (which is exactly why I used eqparbox). Compiling the table and algorithm separately (see below) does not give any errors.

\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}

Any idea's on how to solve this issue so that the table looks like:

\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}

and the algorithm like this:

\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}
3

Just adjust the loading order so that eqparbox comes before arydshln:

Sample output

\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}

Note I have also fixed the markup in your particular comments adding math mode and fixing spacing after an abbreviation dot.

  • This worked like a charm! – jmp111 Jul 17 '14 at 12:16

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.