0

Just look at the output below and I think it's obvious what my problems are:

  1. The wrapped Figure crashed into the lstlistings
  2. The caption didn't notice the huge amount of space to its left that it could use... (Already answered in an answer below)

MWE Problem

These kind of things really make me hate LaTeX, nothing seems to work out of the box...please change my mind by showing me an easy way to solve this without the need of a thousand codelines and custom commands :D
Here's the MWE code, keep in mind: I'm looking for a generic solution for images of different sizes, so only making the caption to span across less lines is not enough - that's a seperate problem.

\documentclass[
    11pt,
    a4paper,
    final,
    twoside=false,
    openright
]{scrbook}

\usepackage{listings,graphicx,wrapfig,xcolor}
\newcommand\crule[3][black]{\textcolor{#1}{\rule{#2}{#3}}}

\begin{document}
\section{Robots}

\begin{wrapfigure}{r}{0.3\textwidth}
    \crule{0.25\textwidth}{5cm}
    \caption{The UR5 robot arm used in this thesis has 8 links and 6 joints (not including its attached robot hand)}
\end{wrapfigure}

Possession her thoroughly\footnote{Blablabla} remarkably terminated man continuing. Removed greater to do ability. You shy shall while but wrote marry. Call why sake has sing pure. Gay six set polite nature worthy. So matter be me we wisdom should basket moment merely. Me burst ample wrong which would mr he could. Visit arise my point timed drawn no. Can friendly laughter goodness man him appetite carriage. Any widen see gay forth alone fruit bed. 

Remain lively hardly needed at do by. Two you fat downs fanny three. True mr gone most at. Dare as name just when with it body. Travelling inquietude she increasing off impossible the. Cottage be noisier looking to we promise on. Disposal to kindness appetite diverted learning of on raptures. Betrayed any may returned now dashwood formerly\footnote{Blablabl2a}. Balls way delay shy boy man views. No so instrument discretion unsatiable to in. 

\begin{itemize}
    \item Defining constants 
\begin{lstlisting}[language=XML]
<xacro:property name="constant_name" value="1" />
<!--Usage - "1" will be inserted below on evaluation-->
${constant_name}
\end{lstlisting}
    \item Doing calculations
\begin{lstlisting}[language=XML]
${1+(height/2)}
\end{lstlisting}
    \item elebrated is in. Am offended as wandered thoughts greatest an friendly. Evening covered in he exposed fertile to. Horses 
\begin{lstlisting}[language=XML]
<xacro:include filename="path_to_file" />
\end{lstlisting}
\end{itemize}

\end{document}

EDIT

I found a trick for the caption issue in another answer: Not writing anything in the caption, breaking the line and then putting the caption text below...but I'm still hoping for a better (but still short!) answer, because I don't want the caption to start in the next line:

\caption{\unskip}
<Caption text here>
6
  • does \begin{wrapfigure}{r}{0.5\textwidth} work for you (aesthetically)? I for one, find it more appealing to the eye.
    – naphaneal
    Jun 9, 2018 at 9:47
  • @naphaneal I'm hoping for an answer that works with different widths, but in this case my original picture is very narrow and high, so the answer is: no, because I don't want huge gaps between the picture and the text
    – Cold_Class
    Jun 9, 2018 at 9:50
  • 1
    By default, linebreaks in lstlisting environments are disabled. If you want to enable them, you can add the option breaklines to the corresponding lstlisting environments.
    – leandriis
    Jun 9, 2018 at 11:10
  • @leandriis This works great for me, I'm glad there is an easy solution for my problem :) You can write this as an answer if you like
    – Cold_Class
    Jun 9, 2018 at 11:32
  • @Cold_Class: Even if the above information solved the problem of listings code overlapping with the wrapfigure's caption, the problem of combining wrapfigure with itemize still persists. A discussion on how to solve this can be found here: Will it ever be possible to use wrapfig with an enumerate or itemize environment?
    – leandriis
    Jun 9, 2018 at 12:53

1 Answer 1

1

The default caption style with KOMA-script is ‘hanging’. You can change that with \setcapindent:

\documentclass[
    11pt,
    a4paper,
    final,
    twoside=false,
    openright
]{scrbook}

\usepackage{listings,graphicx,wrapfig,xcolor}
\newcommand\crule[3][black]{\textcolor{#1}{\rule{#2}{#3}}}

\begin{document}

\section{Robots}

\begin{wrapfigure}{r}{0.32\textwidth}\setcapindent{1em}
\centering
    \crule{0.25\textwidth}{5cm}\\
    \caption{The UR5 robot arm used in this thesis has 8 links and 6 joints (not including its attached robot hand)}
\end{wrapfigure}
Possession her thoroughly\footnote{Blablabla} remarkably terminated man continuing. Removed greater to do ability. You shy shall while but wrote marry. Call why sake has sing pure. Gay six set polite nature worthy. So matter be me we wisdom should basket moment merely. Me burst ample wrong which would mr he could. Visit arise my point timed drawn no. Can friendly laughter goodness man him appetite carriage. Any widen see gay forth alone fruit bed.

Remain lively hardly needed at do by. Two you fat downs fanny three. True mr gone most at. Dare as name just when with it body. Travelling inquietude she increasing off impossible the. Cottage be noisier looking to we promise on. Disposal to kindness appetite diverted learning of on raptures. Betrayed any may returned now dashwood formerly\footnote{Blablabl2a}. Balls way delay shy boy man views. No so instrument discretion unsatiable to in.

\begin{itemize}
    \item Defining constants
\begin{lstlisting}[language=XML]
<xacro:property name="constant_name" value="1" />
<!--Usage - "1" will be inserted below on evaluation-->
${constant_name}
\end{lstlisting}
    \item Doing calculations
\begin{lstlisting}[language=XML]
${1+(height/2)}
\end{lstlisting}
    \item elebrated is in. Am offended as wandered thoughts greatest an friendly. Evening covered in he exposed fertile to. Horses
\begin{lstlisting}[language=XML]
<xacro:include filename="path_to_file" />
\end{lstlisting}
\end{itemize}

\end{document} 

enter image description here

1
  • Thanks, this solves my second point! But not my first, main point - I need a more generic solution as I mentioned: Try to add more text to the caption and you will see, that it still overlaps with the lstlisting. - Keep in mind this is not my real problem, just a MWE that's why specific solutions to this small example won't work for me. In reality I have different pictures and captions, I need a solution that works with all of them.
    – Cold_Class
    Jun 9, 2018 at 10:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .