Document ClassesProblem with lstlistings (caption is overlaping other)

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
one_eddie
Posts: 13
Joined: Thu Sep 04, 2008 11:13 am

Problem with lstlistings (caption is overlaping other)

Post by one_eddie »

I'm using lstlistings. I've changed lstlistingname using \renewcommand{\lstlistingname}{Kod \'zr\'od\l{}owy} command. But there something wrong, please see the picture.

Does anyone know how can I fix it?
Attachments
Latex_bug.png
Latex_bug.png (5.65 KiB) Viewed 8512 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Problem with lstlistings (caption is overlaping other)

Post by localghost »

Providing a minimal working example (MWE) lets us play around with some code and would help us to see where there is something to correct.


Best regards and welcome to the board
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
one_eddie
Posts: 13
Joined: Thu Sep 04, 2008 11:13 am

Problem with lstlistings (caption is overlaping other)

Post by one_eddie »

I found the problem, its because I changed caption width. I don't know if this is a bug or just my lack of knowledge but I know it isn't what I need :)

Here's the MWE:

Code: Select all

\documentclass[a4paper]{memoir}

\usepackage{listings}
\lstset{frame=tb}

\changecaptionwidth
\captionwidth{.6\linewidth}
\captiontitlefont{\footnotesize}

\begin{document}
	\begin{lstlisting}[language=bash,caption=Text text text text text text text text text text text text text text text text text]
	@echo off
	echo Source '%1'
	echo Destination '%2'
	...
	\end{lstlisting}
\end{document}
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Problem with lstlistings (caption is overlaping other)

Post by gmedina »

Hi one_eddie,

you already solved your problem, but you can keep the changes to the caption width and modify the separation between the caption and the code to avoid the overlapping, using belowcaptionskip. Take a look at the following example:

Code: Select all

\documentclass[a4paper]{memoir}

\usepackage{listings}
\lstset{frame=tb}

\changecaptionwidth
\captionwidth{.6\linewidth}
\captiontitlefont{\footnotesize}

\begin{document}
   \begin{lstlisting}[language=bash,caption=Text text text text text text text text text text text text text text text text text,belowcaptionskip=0.4cm]
   @echo off
   echo Source '%1'
   echo Destination '%2'
   ...
   \end{lstlisting}
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
one_eddie
Posts: 13
Joined: Thu Sep 04, 2008 11:13 am

Re: Problem with lstlistings (caption is overlaping other)

Post by one_eddie »

So simple and its in the documentation. I probably missed it while reading docs :)

Thanks
Post Reply