我目前面臨美學問題。我的程式碼/演算法部分的邊界被程式碼內數學標記劃分:
表已使用以下程式碼產生:
\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}
輸出