你好我有以下代码
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{blindtext}
\usepackage{enumerate}
\geometry{paper=a4paper, left=24mm, right=23mm, top=20mm, bottom=20mm}
%Abbildungen
\usepackage{graphicx}
\usepackage[list=true,listformat=simple]{subcaption} %Mehrere Bilder in einer figure
\usepackage[justification=raggedright]{caption}
%Zentrierte Beschriftungen
\usepackage{float} %H-Figure Typ
\usepackage[labelfont={bf,sf},font={small},%
labelsep=space]{caption}
\usepackage{rotating}
\usepackage{listings}
\lstset{
basicstyle=\ttfamily\footnotesize,
xleftmargin=.1\textwidth,
}
\usepackage[wide]{sidecap}
\usepackage{newfloat}
\DeclareFloatingEnvironment[placement={!ht},name=]{listing}
\sidecaptionvpos{listing}{c}
\makeatletter
\makeatother
\begin{document}
\blindtext
(\cite{pykrige}).
\begin{SClisting}
\begin{lstlisting}[language=Python]
from traceback import print_tb
import numpy as np
from pykrige.ok import OrdinaryKriging
from pykrige.kriging_tools import write_asc_grid
import pykrige.kriging_tools as kt
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
\end{lstlisting}
\captionsetup{style=base}
\caption{}
\label{lst:einf}
\end{SClisting}
\blindtext
\begin{SClisting}
\begin{lstlisting}[language=Python]
def load_data():
dflm = dfl
return dflm
def get_data(dflm):
return {
"lons": dflm['Longitude'].values,
"lats": dflm['Latitude'].values,
"values": dflm['ValueHeight'].values
}
dflm = load_data()
base_data = get_data(dflm)
\end{lstlisting}
\captionsetup{style=base}
\caption{}
\label{lst:laden}
\end{SClisting}
\begin{figure}[H]
\centering
\includegraphics{Unbenannt.PNG}
\caption{these captions should remain as they are}
\label{fig:my_label}
\end{figure}
\end{document}
但是,我希望右边缘的数字位于一个平面上,并被括号包围。我知道我必须更改剪切\captionsetup{style=base}
,但我不知道该怎么做
困难:我在同一部作品中有插图,因此代码的标题定义必须是这样的,它只影响代码,而插图的标题保持和以前一样。
答案1
更新在后续问题之后。
此代码将把标题用括号放在右边框上。
它使用 \usepackage[margincaption,leftbody]{sidecap}
并定义一种新的标题格式来定位标题和添加括号。
仅\captionsetup[lstlisting]{format=myformat}
myformat
适用于列表的标题。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{blindtext}
\usepackage{enumerate}
\geometry{paper=a4paper, left=24mm, right=23mm, top=20mm, bottom=20mm, showframe} % added showframe <<<<<<<<<<<<<<<<<<<<<<<<
%Abbildungen
\usepackage{graphicx}
\usepackage[list=true,listformat=simple]{subcaption} %Mehrere Bilder in einer figure
%Zentrierte Beschriftungen
%\usepackage{float} %H-Figure Typ
\usepackage{rotating}
\usepackage[labelfont={bf,sf},font={small},labelsep=space]{caption}
\DeclareCaptionFormat{myformat}{\hspace*{\dimexpr-2\marginparsep -\marginparwidth-3ex\relax}[#1]}% added <<<<<<<<<
\captionsetup[lstlisting]{format=myformat}% apply only to lstlisting
\usepackage{listings}
\lstset{
basicstyle=\ttfamily\footnotesize,
xleftmargin=.1\textwidth,
}
\usepackage[margincaption,leftbody]{sidecap} % changed <<<<<<<<<<<<<<<<<<<
\usepackage{newfloat}
\DeclareFloatingEnvironment[placement={!ht},name=]{listing}
\sidecaptionvpos{listing}{c} % in here
\begin{document}
\blindtext
(\cite{pykrige}).
\begin{SClisting}
\begin{lstlisting}[language=Python]
from traceback import print_tb
import numpy as np
from pykrige.ok import OrdinaryKriging
from pykrige.kriging_tools import write_asc_grid
import pykrige.kriging_tools as kt
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
\end{lstlisting}
\caption{}
\label{lst:einf}
\end{SClisting}
\blindtext
\begin{SClisting}
\begin{lstlisting}[language=Python]
def load_data():
dflm = dfl
return dflm
def get_data(dflm):
return {
"lons": dflm['Longitude'].values,
"lats": dflm['Latitude'].values,
"values": dflm['ValueHeight'].values
}
dflm = load_data()
base_data = get_data(dflm)
\end{lstlisting}
\caption{}
\label{lst:laden}
\end{SClisting}
\begin{figure}[hb!]
\centering
\includegraphics{example-image}
\caption{these captions should remain as they are}
\label{fig:my_label}
\end{figure}
\end{documen