我目前面临一个美学问题。我的代码/算法部分的边框被代码内的数学标记分割了:
表格是使用以下代码生成的:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath, amsfonts}
\usepackage{listings}
\title{Title}
\author{Author}
\date{Date}
\begin{document}
\maketitle
\lstset{
numbers=left,
numberstyle=\small,
numbersep=8pt,
frame = single,
language=Python,
framexleftmargin=15pt
}
\begin{lstlisting}[escapeinside={(*}{*)}]
if (*$\exists s \in S \subset \mathbb{R}^2 \times \{\text{label } | \text{ label } \in \{0,1\} \}$*) with label 1:
(*$r = \underset{\text{label(s) = 1} }{\max ||s||}$*)
else:
(*$r = \underset{\text{label(s) = 0} }{\min ||s||} - 10^{-1000} $*)
return B[0, r]
\end{lstlisting}
\end{document}
有人知道我该如何让垂直边框在数学标记下保持连续吗?或者至少删除垂直边框?
顺便说一下,我在 Overleaf 工作。
谢谢你!
答案1
您可以使用它tcblisting
来为您生成框架。
或者,要删除垂直边框,只需指定frame=none
。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tcolorbox}
\usepackage{amsmath, amssymb}
\tcbuselibrary{listings, breakable, skins}
\title{Title}
\author{Author}
\date{Date}
\newtcblisting{mylisting}{
enhanced,
breakable,
listing only,
sharp corners,
arc=0mm,
colback=white,
boxsep=1mm,
top=0mm,
bottom=0mm,
left=6mm,
right=1mm,
listing options={
numbers=left,
numberstyle=\small,
numbersep=8pt,
language=Python,
escapeinside={(*}{*)}
}
}
\begin{document}
\maketitle
\begin{mylisting}
if (*$\exists s \in S \subset \mathbb{R}^2 \times \{\text{label } | \text{ label } \in \{0,1\} \}$*) with label 1:
(*$r = \underset{\text{label(s) = 1} }{\max ||s||}$*)
else:
(*$r = \underset{\text{label(s) = 0} }{\min ||s||} - 10^{-1000} $*)
return B[0, r]
\end{mylisting}
\end{document}
答案2
listings.sty
这是标题下的文档中解释的一个错误8.2
修改后的内容MWE
为:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{moreverb}
\usepackage{amsmath,amsfonts,listings}
\usepackage{mdframed}
\begin{document}
\lstset{
numbers=left,
numberstyle=\small,
numbersep=2pt,
%frame = single,
language=Python,
framexleftmargin=15pt
}
\begin{verbatimwrite}{temp.c}
if (*$\exists s \in S \subset \mathbb{R}^2 \times \{\text{label } | \text{ label } \in \{0,1\} \}$*) with label 1:
(*$r = \underset{\text{label(s) = 1} }{\max ||s||}$*)
else:
(*$r = \underset{\text{label(s) = 0} }{\min ||s||} - 10^{-1000} $*)
return B[0, r]
\end{verbatimwrite}
\begin{mdframed}
\lstinputlisting[escapeinside={(*}{*)}]{./temp.c}
\end{mdframed}
\end{document}
输出