Document Classes ⇒ Problem with lstlistings (caption is overlaping other)
Problem with lstlistings (caption is overlaping other)
Does anyone know how can I fix it?
- Attachments
-
- Latex_bug.png (5.65 KiB) Viewed 9215 times
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Problem with lstlistings (caption is overlaping other)
Best regards and welcome to the board
Thorsten¹
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Problem with lstlistings (caption is overlaping other)
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}Problem with lstlistings (caption is overlaping other)
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}Re: Problem with lstlistings (caption is overlaping other)
Thanks