
~ 안에Jupyter 인 앤 아웃 스타일그리고fancyvrb의 마지막 줄 간격이 이상합니다.LaTeX 내에서 Jupyter 스타일을 구현하기 위한 깔끔한 솔루션을 요청했습니다.
지금까지 훌륭했고 꽤 훌륭하고 견고하게 작동합니다. 다만, 입출력 숫자가 왼쪽으로 넘치지 않도록 하면 완벽할 것 같습니다. 큰 노력 없이도 그게 가능할까?
내가 작업하고 있는 최소한의 예는 다음의 답변에서 채택되었습니다.fancyvrb의 마지막 줄 간격이 이상합니다..
답변1
tcolorbox
를 지정하여 을 오른쪽으로 이동할 수 있습니다 left skip
. 아래 코드에서는 프롬프트 너비와 출력 상자와의 구분에 대해 두 가지 길이를 제공했습니다.
\documentclass[twoside,a4paper]{scrartcl}
%-------
% Typography
%-------
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{textcomp}
\usepackage{dsfont}
\usepackage{microtype}
\usepackage[onehalfspacing]{setspace}
%-------
% Notebook Styling
%-------
\usepackage[most]{tcolorbox}
\tcbuselibrary{listings}
\tcbset{nobeforeafter}
\definecolor{outcolor}{HTML}{D84315}
\newlength{\promptwidth}
\setlength{\promptwidth}{30pt}
\newlength{\promptsep}
\setlength{\promptsep}{5.5pt}
\newcommand{\prompt}[4]{%
\makebox[0pt][r]{\texttt{\color{#2}#1[#3]:#4}}\vspace{-\baselineskip}%
}
\newcounter{NBin}
\newtcblisting{NotebookOut}{
breakable,
boxrule=.5pt,
size=fbox,
left skip = \promptwidth + \promptsep,
pad at break*=1mm,
opacityfill=1,
phantom=\refstepcounter{NBin},
title=\prompt{}{outcolor}{\theNBin}{\hspace{\promptsep}},
fonttitle=\linespread{1}\small,
attach title to upper,
listing only,
listing options={
language=python,
basicstyle=\linespread{1}\small\ttfamily,
basewidth=.5em,
aboveskip=0pt,
belowskip=0pt,
showstringspaces=false,
}
}
\begin{document}
\begin{NotebookOut}
print('Hello World!')
print('Hello World!')
\end{NotebookOut}
\noindent
Text
\begin{NotebookOut}
print('Hello World!')
print('Hello World!')
\end{NotebookOut}
\end{document}