5

I've been able to increase the width of the horizontal lines honoring the second answer in LaTeX tables: How do I make thicker or thinner horizontal lines (typically \hline)?. Now, I'd like to do the same in algorithmic & listings environment but I don't know how to do that. Is that possible? and if so, how?

For instance, the following example

\documentclass[10pt]{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{listings}
\usepackage{makecell}

\begin{document}
\newcommand{\blah}{blah blah blah blah blah\\}
\newcommand{\hlinethick}{\Xhline{4\arrayrulewidth}}

\blah \blah \blah

\begin{lstlisting}[frame=tb]
    return 1;
\end{lstlisting}

\begin{algorithm}
    \caption{My algorithm.}
\begin{algorithmic}[1]
    \Procedure{Algorithm}{}
    \State \textbf{return} $mat$
    \EndProcedure
\end{algorithmic}
\end{algorithm}

\blah \blah \blah

\begin{table}
  \begin{center}
  \caption{My table.}
    \begin{tabular}{c r r r}
    \hlinethick
      header1 & header2 & header3 \\
    \hline
      $T_{s}$              & 7 & 14 & 21 \\
      $T_{i}$              & 3 &  3 & 20 \\
    \hlinethick
    \end{tabular}
  \end{center}
\end{table}

\end{document}

results in

enter image description here

1
  • Regarding listings, see section 4.11 in the doc: the framerule key controls the width of rules.
    – jub0bs
    Nov 13, 2014 at 15:44

1 Answer 1

5

The listings package provides a key called framerule, which takes a dimension value (e.g. 2pt) and determines the thickness of rules that used in listings.

Changing the thickness of rules used in algorithms is more complicated. The algorithm package delegates the drawing of those rules to the float package, which doesn't allow the user to tweak the thickness in any straightforward fashion; instead, the thickness is hardcoded in the definition of so-called floatstyles. Therefore, your only option is to redefine the floatstyle of interest (the default one, ruled, here).

For convenience and better maintainability, I've defined a new length macro (called \hrulethickness) that governs the thickness of rules used in tables, listings, and algorithms of your document. See below.

enter image description here

\documentclass[10pt]{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{listings}
\usepackage{makecell}

% one length to rule them all
\newlength\hrulethickness
\setlength\hrulethickness{4\arrayrulewidth}
\newcommand{\hlinethick}{\Xhline{\hrulethickness}}

% `listings' settings
\lstset{framerule=\hrulethickness}

% redefinition of the `ruled' floatstyle
% (defined in the `float' package, used by the `algorithm' package)
\makeatletter
\renewcommand\fs@ruled{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled
  \def\@fs@pre{\hrule height \hrulethickness depth0pt \kern2pt}%
  \def\@fs@post{\kern2pt\hrule height \hrulethickness depth0pt \relax}%
  \def\@fs@mid{\kern2pt\hrule height \hrulethickness depth0pt \kern2pt}%
  \let\@fs@iftopcapt\iftrue}
\makeatother

\begin{document}

\newcommand{\blah}{blah blah blah blah blah\\}
\blah \blah \blah

\begin{lstlisting}[frame=tb]
    return 1;
\end{lstlisting}

\begin{algorithm}
    \caption{My algorithm.}
\begin{algorithmic}[1]
    \Procedure{Algorithm}{}
    \State \textbf{return} $mat$
    \EndProcedure
\end{algorithmic}
\end{algorithm}

\blah \blah \blah

\begin{table}
  \begin{center}
  \caption{My table.}
    \begin{tabular}{c r r r}
    \hlinethick
      header1 & header2 & header3 \\
    \hline
      $T_{s}$              & 7 & 14 & 21 \\
      $T_{i}$              & 3 &  3 & 20 \\
    \hlinethick
    \end{tabular}
  \end{center}
\end{table}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .