Articles of listings

Why is listings' frame width a little larger then \textwidth?

Here is the sample code: \documentclass[]{article} \usepackage{listings} \lstset{ basicstyle=\ttfamily\footnotesize, frame=single, % adds a frame around the code } \begin{document} \setlength{\fboxsep}{0pt} \noindent\makebox[\linewidth]{\rule{\textwidth}{1pt}} abc \begin{lstlisting} abc \end{lstlisting} \end{document} And the screen shot of the result: Even I set the \fboxsep to zero, I still get the same result. Are there any way to make it a little […]

Why can't I compile the simplest TeX file of only 6 lines?

\documentclass{article} \usepackage[adobefonts]{ctex} \usepackage[os=win]{menukeys} \usepackage{listings} \begin{document} \end{document} The simplest TeX file above cannot be compiled with xelatex, the errors are: (/opt/local/texlive/2014/texmf-dist/tex/latex/adjustbox/adjustbox.sty (/opt/local/texlive/2014/texmf-dist/tex/latex/xkeyval/xkeyval.sty (/opt/local/texlive/2014/texmf-dist/tex/generic/xkeyval/xkeyval.tex)) (/opt/local/texlive/2014/texmf-dist/tex/latex/adjustbox/adjcalc.sty) (/opt/local/texlive/2014/texmf-dist/tex/latex/adjustbox/trimclip.sty (/opt/local/texlive/2014/texmf-dist/tex/latex/collectbox/collectbox.sty) (/opt/local/texlive/2014/texmf-dist/tex/latex/adjustbox/tc-xetex.def)) (/opt/local/texlive/2014/texmf-dist/tex/latex/ifoddpage/ifoddpage.sty) (/opt/local/texlive/2014/texmf-dist/tex/latex/varwidth/varwidth.sty)) (/opt/local/texlive/2014/texmf-dist/tex/latex/relsize/relsize.sty) (/opt/local/texlive/2014/texmf-dist/tex/latex/catoptions/catoptions.sty) (/opt/local/texlive/2014/texmf-dist/tex/latex/oberdiek/kvoptions.sty (/opt/local/texlive/2014/texmf-dist/tex/generic/oberdiek/ltxcmds.sty) (/opt/local/texlive/2014/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty (/opt/local/texlive/2014/texmf-dist/tex/generic/oberdiek/infwarerr.sty) (/opt/local/texlive/2014/texmf-dist/tex/generic/oberdiek/etexcmds.sty (/opt/local/texlive/2014/texmf-dist/tex/generic/oberdiek/ifluatex.sty))))) (/opt/local/texlive/2014/texmf-dist/tex/latex/listings/listings.sty (/opt/local/texlive/2014/texmf-dist/tex/latex/listings/lstmisc.sty) (/opt/local/texlive/2014/texmf-dist/tex/latex/listings/listings.cfg)) (/opt/local/texlive/2014/texmf-dist/tex/xelatex/xecjk/xeCJK-listings.sty ! LaTeX Error: Option clash for package xeCJK. See the LaTeX manual or LaTeX Companion […]

How would you typeset this type of programming documentation?

Consider, for example, this pdf document which defines the standard for the C programming language. The description of the library functions follows a fixed structure composed of three sections, as shown in the picture below: synopsis, description and returns with numbered paragraphs. To reproduce this structure, I would: Define a subsection (or subsubsection) heading with […]

Frame around minipage containing listing in beamer

I am working on the sheets of a course on LaTeX and would like to have several sheets in which you see on the left an example of a source document and on the right its output. I have this working now with listings and minipage, but I also want a frame around the page […]

Listings line numbers and figure

I’m using listings to typeset some C inside a figure environment next to a diagram, and I have the numbers on the left. My problem is in two-column mode the line numbers appear in what should be the margin, outside the text area (i.e., numbers are not justified with the left-hand side of the column, […]

Saving language preferences for inputing source code

Using the listings package, I am trying to input a Java source file into my document using a specified, user-defined style. This works just fine if I have the specified style definition in the same document. However, I wish to save the style so that I can use it without having the definition directly in […]

How can I put lstlisting block into subfloat block?

I’m trying to compile my document but it’s exploding. I’ve narrowed it down to this section: \begin{figure}[h] \caption{These are my awesome code snippets} \subfloat[This code runs every cycle.]{ \begin{lstlisting} static uint64_t i = 0; void every_cycle() { if (i > 0) i–; } \end{lstlisting} } \hfill \subfloat[This code runs whenever.]{ \begin{lstlisting} uint64_t next_num() { return […]

Increment line number counter in Listing by a value other than one

I’m trying to write some code listings, but the language I am using refers to line numbers that increment by 4. This is similar to how line numbers in BASIC were incremented by 10 per line. I tried using the option stepnumber=4 but I obviously misinterpreted what this option was intended to do. It skips […]

numbering tcolorbox toc

I’m writing a quite large document and would like to make a toc of used boxes. I’m using the tcolorbox package because i like the way it gives you freedom to modify the appearance of the boxes. While generating the toc using the options provided by the package i get extra numbering within the toc. […]

Listing inside tabularx?

I have a tabularx environment where I want to put an lstlisting into. But Latex fails to compile it. Testcase: \documentclass[a4paper,12pt]{scrreprt} \usepackage[utf8x]{inputenc} \usepackage{tabularx} \usepackage{listings} \begin{document} \begin{tabularx}{\textwidth}{lX} First column & \begin{lstlisting} Sample text \end{lstlisting} \\ \end{tabularx} \end{document} I always get a ! Argument of \lst@next has an extra }. Two questions: What’s causing it? How can […]