我想装饰一些列表仅出于教学原因。
这是起始代码,我可以在其中绘制一条线,但仍然无法生成框架。我该怎么做?
\documentclass[12pt,a4paper]{article}
\usepackage[skins, many, minted, breakable, hooks]{tcolorbox}
\usetikzlibrary{tikzmark,fit}
\makeatletter
% Source: https://tex.stackexchange.com/a/124688/6880
\newcommand{\mynewminted}[3]{%
\newminted[#1]{#2}{#3}%
\tcbset{myminted/#1/.style = {
minted language = #2,
minted options = {#3}
}}
}
\newcommand{\create@new@coding@env@title}[4]{%
\mynewminted{for-coding-#1}{python}{escapeinside=||}
\newtcblisting[]{coding-#1}[2][1]{%
listing only,
width = ##1\linewidth,
title = ##2,
myminted/for-coding-python,
}
}
\create@new@coding@env@title{python}{\Large\faPython}{2mm}{1.8mm}
\makeatother
\begin{document}
\begin{coding-python}{Basic loop
Python}
|\tikzmark{topleft}|def oneloop(n): |\tikzmark{topright}|
for i in range(n):
print(i**2) |\tikzmark{downright}|
print(oneloop(n))
\end{coding-python}
\begin{tikzpicture}
\tikz[remember picture] \draw[overlay, red] (pic cs:topright) -- (pic cs:downright);
\end{tikzpicture}
\end{document}
答案1
这是一个可以帮助其他人的解决方案。我不是一个能解决自己问题的聪明人因为我使用了我的以下旧帖子:https://tex.stackexchange.com/a/78566/6880。输出如下面的屏幕截图所示。
\documentclass[12pt,a4paper]{article}
\usepackage[skins, many, minted, breakable, hooks]{tcolorbox}
\usetikzlibrary{tikzmark,calc,fit}
\makeatletter
% Source: http://tex.stackexchange.com/a/50054/3954
\newcommand\myframe[4][-1ex]{%
\tikz[remember picture,overlay,pin distance=0cm]{
\draw[draw=#4,line width=1pt,fill=#4!20,rectangle,rounded corners, opacity=0.2]
( $ (pic cs:#2) + (-1ex,2ex) $ ) rectangle ( $ (pic cs:#3) + (1ex,#1) $ );
\draw[draw=#4,line width=1pt,rectangle,rounded corners, opacity=1]
( $ (pic cs:#2) + (-1ex,2ex) $ ) rectangle ( $ (pic cs:#3) + (1ex,#1) $ );
}
% Source: https://tex.stackexchange.com/a/124688/6880
\newcommand{\mynewminted}[3]{%
\newminted[#1]{#2}{#3}%
\tcbset{myminted/#1/.style = {
minted language = #2,
minted options = {#3}
}}
}
\newcommand{\create@new@coding@env@title}[4]{%
\mynewminted{for-coding-#1}{python}{escapeinside=||}
\newtcblisting[]{coding-#1}[2][1]{%
listing only,
width = ##1\linewidth,
title = ##2,
myminted/for-coding-python,
}
}
\create@new@coding@env@title{python}{\Large\faPython}{2mm}{1.8mm}
\makeatother
\begin{document}
\begin{coding-python}{Basic loop
Python}
|\tikzmark{topleft}|def oneloop(n):
for i in range(n):
print(i**2) |\tikzmark{downright}|
print(oneloop(n))
\end{coding-python}
\myframe[-2ex]{topleft}{downright}{red}
\end{document}