Generallstlisting and padding

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
eleanor
Posts: 19
Joined: Sat Oct 03, 2009 6:03 pm

lstlisting and padding

Post by eleanor »

Hi, I have a problem with using lstlisting. Well, there is too much padding (space between the border and the text) there:

http://www.w3schools.com/CSS/css_padding.asp (just to make sure that we're on the same page about what I'm talking about).

I want to minimize this padding to 2pt (or some other number). Do you have any idea how would I do that?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

lstlisting and padding

Post by localghost »

Take a look at Section 4.10 (Margins and line shape, p. 33f) and Section 4.11 (Frames, p. 34ff) of the listings manual.


Best regards and welcome to the board
Thorsten¹
eleanor
Posts: 19
Joined: Sat Oct 03, 2009 6:03 pm

lstlisting and padding

Post by eleanor »

Hi, I've tried most of the options listed there but without the effect, here's the lstset that I'm using:

Code: Select all

\lstset {
    language=c++,                  % language code
    basicstyle=\footnotesize,      % font size
    numbers=none,                  % where to put line numbers
    numberstyle=\footnotesize,     % numbers size
    numbersep=5pt,                 % how far the line numbers are from the code
    backgroundcolor=\color{white}, % background color
    showspaces=false,                          % show spaces (with underscores)
    showstringspaces=false,            % underline spaces within strings
    showtabs=false,                            % show tabs using underscores
    frame=single,                  % adds a frame around the code
    tabsize=4,                     % default tabsize
    breaklines=true,                  % automatic line breaking
    columns=fullflexible,
    breakautoindent=false,
    framerule=1pt,
    xleftmargin=0pt,
    xrightmargin=0pt,
    breakindent=0pt,
    resetmargins=true
}
Any ideas why it doesn't work?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

lstlisting and padding

Post by localghost »

Use options like framesep introduced in Section 4.11 of the manual.
tilao
Posts: 1
Joined: Thu Feb 25, 2010 2:17 pm

lstlisting and padding

Post by tilao »

Hi,

I don't know if the problem is solved but I encountered a similar issue and I solved it by writing \noindent before to include my listing.

I'm now encountering an other issue I can't solve. I have a listing side by side with an explanation. I use the minipage to display my boxes, I wrote something like this :

Code: Select all

\noindent
\begin{minipage}[t]{.43\linewidth}
\begin{lstlisting}
digraph aGraph { 
	some other code
}
\end{lstlisting}
\end{minipage}
\hspace{.02\linewidth}
\begin{minipage}[t]{.54\linewidth}
some text
\end{minipage}
\hfill
Everything is almost fine, but the base line of the listing is under the base line of the text and its looks ugly.

Here are my settings :

Code: Select all

\lstdefinelanguage{dot}{keywords={digraph, label, ....},sensitive=true}
\lstset{language=dot, caption={Graphviz}, label={listing:Graphviz}, basicstyle=\small, captionpos=b, aboveskip=0pt, frame=b, tabsize=2, framesep=0pt, framexbottommargin=8pt}
If I update \lstset and write "frame=tb" I get a line on the top ... and the base line is correct.
If I remove it, it goes wrong again. Like if a special framesep is added when no frame is used ?

I got a working solution by writing aboveskip=-8pt ... but I'm not satisfied with this hack.
Did I got wrong somewhere or did I missed an other parameter of the lstlisting package ?

Best Regards,
Pierre.
Post Reply