Text Formattingabout lstlisting caption alignment

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
phenoboy
Posts: 2
Joined: Sun May 22, 2011 7:02 pm

about lstlisting caption alignment

Post by phenoboy »

I'm having the following problem. Text in caption is not exactly left justified, there's small gap. I'd like the letter E be justified with o in this picture. Following figure illustrates the problem:

Image

Here are the modifications I've done

Code: Select all

\DeclareCaptionFormat{listing}{
%\setlength{\fboxsep}{0pt}
\parbox[bottom][0pt][c]{\textwidth}{\hspace{0pt}#1#2#3}}

\DeclareCaptionFont{black}{\color{black}}

\captionsetup[lstlisting]{format=listing,labelfont=black,textfont=black,
       singlelinecheck=true, margin=0pt, font={tt,small,bf}}

Code: Select all

\lstset{
showstringspaces=false,
rulesepcolor=\color{harmaa},
columns=l,
tabsize=2,
numbers=left,
frame=lines,
numberstyle=\tiny,
keywordstyle=\color{red}\bfseries\underbar\emph,
	   backgroundcolor=\color{white},
       basicstyle=\small\ttfamily\onehalfspacing,
       columns=fullflexible,
       commentstyle=\color{gray}\textit,
       numberstyle=\tiny,
       breaklines=true,
       numberstyle=\tiny,
       numbersep=5pt,
       framextopmargin=10pt,
       morecomment=[l]{//},
       stringstyle=\color{DarkGray}\textit,
   }
Last edited by phenoboy on Wed May 25, 2011 6:56 pm, edited 1 time in total.

Recommended reading 2024:

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

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

sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

about lstlisting caption alignment

Post by sommerfee »

Please post a complete example code next time, otherwise we are unable to reproduce and examine the problem.

But I guess the space is because of the following definition:

Code: Select all

\DeclareCaptionFormat{listing}{
%\setlength{\fboxsep}{0pt}
\parbox[bottom][0pt][c]{\textwidth}{\hspace{0pt}#1#2#3}}
Try using the following instead:

Code: Select all

\DeclareCaptionFormat{listing}{%
%\setlength{\fboxsep}{0pt}%
\parbox[bottom][0pt][c]{\textwidth}{\hspace{0pt}#1#2#3}}
phenoboy
Posts: 2
Joined: Sun May 22, 2011 7:02 pm

about lstlisting caption alignment

Post by phenoboy »

I found the solution. This is correct:

Code: Select all

\DeclareCaptionFormat{listing} {
  \parbox{\textwidth}{\hspace{-0.2cm}#1#2#3}
}
Post Reply