Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using the listings package.

I would like my listings to have a heavy rule above the caption, so it looks like the \floatstyle{ruled}.

So it would look like:

a bold line ===

caption

rule ---

code

rule ---

share|improve this question

migrated from stackoverflow.com Mar 8 '12 at 17:16

This question came from our site for professional and enthusiast programmers.

    
Give a example file. I will give a solution –  Mu30 Mar 9 '12 at 14:28
    
Welcome to TeX.SE. Please keep in mind that it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Basically, show some work by getting the example as far as you can. –  Peter Grill Mar 10 '12 at 3:59

1 Answer 1

The packages listings provides the option frame=single which draws a single line above and below the environment itself. So you have to add a single bold line before the caption is set. Therefore I am using the command pretocmd provided by etoolbox.

\documentclass{article}
\usepackage{listings}
\usepackage{etoolbox}
\makeatletter
\lstset{frame=lines}
\pretocmd\lst@makecaption{\noindent{\rule{\linewidth}{2pt}}}{}{}
\makeatother

\begin{document}
\begin{lstlisting}[caption={Some Caption}]
    static uint64_t i = 0;
    void every_cycle()
    {
        if (i > 0)
            i--;
    }

        uint64_t next_num()
    {
        return (i += 0x100);
    }
\end{lstlisting}
Text
\begin{lstlisting}
    static uint64_t i = 0;
    void every_cycle()
    {
        if (i > 0)
            i--;
    }

        uint64_t next_num()
    {
        return (i += 0x100);
    }
\end{lstlisting}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.