3

I have tried to include SQL code in my text. Unfortunately I am not very familiar with it and have cobbled together the code from various forums. Now, as the title says, I have two captions for the whole thing. But I only want to have one at the bottom left.

Do you know how to remove the top one?

\documentclass[%
    fontsize=11pt, % Schriftgröße
    twoside=off % kein einseitiges Layout
]{scrbook} % Dokumentenklasse: KOMA-Script Book

\usepackage[tablewithout, figurewithout]{caption}

\usepackage{listings}
\usepackage{xcolor}

\lstloadlanguages{SQL}
\renewcommand\lstlistingname{Quellcode}
\renewcommand\lstlistlistingname{Quellcode}

\lstset{ 
    language=SQL,
    basicstyle=\ttfamily,
    keywordstyle=\color{blue}\bfseries,
    stringstyle=\color{red},
    commentstyle=\color{green},
    breaklines=true,
    numbers=left, % Zeilennummern links anzeigen
    numberstyle=\tiny\color{gray}, % Stil der Zeilennummern
    stepnumber=1, % Jede Zeile nummerieren
    numbersep=5pt, % Abstand der Nummern vom Code
    numberbychapter=false, %Caption Nummer beginnt bei eins und wird von vorne nach hinten durchgezählt
    captionpos=bottom
}

\captionsetup[lstlisting]{%
    position=below,
    justification=raggedright,
    singlelinecheck=false,
    labelfont=bf
}

\begin{document}
\begin{lstlisting}[language=SQL, label={code:SQL}, caption={SQL Code um Attribute an Pfade anzuheften.}]
SELECT cl.Id_Cul,
       cl."begin",
       cl."end",
       co.Id_Points AS Id_Points_1,
       CASE
           WHEN co."Height [cm" = -1 THEN NULL
           ELSE co."Height [cm"
       END AS "Height1 [cm]",
       CASE
           WHEN co."width [cm]" = -1 THEN NULL
           ELSE co."width [cm]"
       END AS "width1 [cm]",
       co.Form AS Form1,
       ...,
       co2.Comment AS Comment2,
       co2.x AS x2,
       co2.y AS y2,
       co2.z AS z2
FROM Culverts_own_line_2 AS cl
LEFT JOIN Culverts_own_2 AS co ON cl."begin" = co.id
LEFT JOIN Culverts_own_2 AS co2 ON cl."end" = co2.id
ORDER BY co2.id
\end{lstlisting}

\end{document}

enter image description here

1 Answer 1

3

The captionpos key takes either t or b as value, not bottom:

\documentclass[%
    fontsize=11pt, % Schriftgröße
    twoside=off % kein einseitiges Layout
]{scrbook} % Dokumentenklasse: KOMA-Script Book

\usepackage[tablewithout, figurewithout]{caption}

\usepackage{listings}
\usepackage{xcolor}

\lstloadlanguages{SQL}
\renewcommand\lstlistingname{Quellcode}
\renewcommand\lstlistlistingname{Quellcode}

\lstset{ 
    language=SQL,
    basicstyle=\ttfamily,
    keywordstyle=\color{blue}\bfseries,
    stringstyle=\color{red},
    commentstyle=\color{green},
    breaklines=true,
    numbers=left, % Zeilennummern links anzeigen
    numberstyle=\tiny\color{gray}, % Stil der Zeilennummern
    stepnumber=1, % Jede Zeile nummerieren
    numbersep=5pt, % Abstand der Nummern vom Code
    numberbychapter=false, %Caption Nummer beginnt bei eins und wird von vorne nach hinten durchgezählt
    captionpos=b
}

\captionsetup[lstlisting]{%
    position=below,
    justification=raggedright,
    singlelinecheck=false,
    labelfont=bf
}

\begin{document}
\begin{lstlisting}[language=SQL, label={code:SQL}, caption={SQL Code um Attribute an Pfade anzuheften.}]
SELECT cl.Id_Cul,
       cl."begin",
       cl."end",
       co.Id_Points AS Id_Points_1,
       CASE
           WHEN co."Height [cm" = -1 THEN NULL
           ELSE co."Height [cm"
       END AS "Height1 [cm]",
       CASE
           WHEN co."width [cm]" = -1 THEN NULL
           ELSE co."width [cm]"
       END AS "width1 [cm]",
       co.Form AS Form1,
       ...,
       co2.Comment AS Comment2,
       co2.x AS x2,
       co2.y AS y2,
       co2.z AS z2
FROM Culverts_own_line_2 AS cl
LEFT JOIN Culverts_own_2 AS co ON cl."begin" = co.id
LEFT JOIN Culverts_own_2 AS co2 ON cl."end" = co2.id
ORDER BY co2.id
\end{lstlisting}

\end{document}

enter image description here

2
  • Thank you @samcarter_is_at_topanswers.xyz ! You solved the Problem
    – FloB
    Commented May 26 at 19:52
  • 1
    @FloB You're welcome! Commented May 26 at 19:53

You must log in to answer this question.

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