我想要调整tcolorbox
我正在制作的类型。
我特别想在图像的一侧绘制边框,类似于minted
通过指定选项允许仅在一侧绘制边框frame=leftline
。
我得到了以下代码:
\documentclass[a5paper]{article}
\usepackage[T1]{fontenc}
\usepackage[]{minted}
\usepackage[skins]{tcolorbox}
\usepackage{lineno}
\def\gobble#1{}
\renewcommand\DeleteFile[1]{}
\usepackage{xparse}
\ExplSyntaxOn
\box_new:N \l_fvrb_box
\tl_new:N \l_fvrb_tl
\RenewDocumentCommand \FancyVerbFormatLine { m }
{
\hbox_set:Nn \l_fvrb_box { #1 }
\dim_compare:nNnTF { \box_wd:N \l_fvrb_box }>{ \linewidth }
{
\tl_set:Nn \l_fvrb_tl { #1 }
\fvrb_use_tl:N \l_fvrb_tl
}
{%box fits
\box_use:N \l_fvrb_box
}
}
\cs_new:Npn \fvrb_use_tl:N #1
{
\group_begin:
\null\hfill\vbox_set:Nn \l_fvrb_box
{\hsize=\linewidth
\renewcommand\thelinenumber
{
\ifnum\value{linenumber}=1\relax\else
$\rightarrow$
\fi
}
\begin{internallinenumbers}
\advance\hsize by -2em
\hspace*{-2em}\tl_use:N #1
\end{internallinenumbers}
}
\box_use:N \l_fvrb_box
\group_end:
}
\ExplSyntaxOff
\definecolor{mintedbg}{RGB}{250,255,250}
\usepackage{etoolbox}
\BeforeBeginEnvironment{minted}{\begin{tcolorbox}[enhanced,
width=\linewidth,
enlarge top by=3pt,enlarge bottom by=3pt,
enlarge left by=3pt,enlarge right by=3pt,
frame hidden,boxrule=0pt,top=1mm,bottom=1mm,
colframe=green!30!black, colbacktitle=green!50!yellow,
coltitle=black, colback=mintedbg,
borderline={.8pt}{-0.5pt}{blue!87!green!13, sharp corners},
borderline={.9pt}{-3pt}{blue!70!green!30, sharp corners},
borderline={1pt}{-5.5pt}{blue!53!green!47, sharp corners}]}%
\AfterEndEnvironment{minted}{\end{tcolorbox}}%
\begin{document}
\begin{minted}{latex}
%Preamble
\usepackage[]{minted}
\usepackage[fancyvrb=true]{listings}
\usepackage{tcolorbox}
\usepackage{etoolbox}
\BeforeBeginEnvironment {minted} { \begin{tcolorbox} } \AfterEndEnvironment {minted} { \end{tcolorbox} }%
\usepackage{lipsum}
\end{minted}
\end{document}
理想情况下,我想要一种与 非常相似的样式minted
,frame=leftline
但具有示例中所示的多条(边界)线。
答案1
一种选择:
\documentclass[a5paper]{article}
\usepackage[T1]{fontenc}
\usepackage[]{minted}
\usepackage[skins]{tcolorbox}
\usepackage{lineno}
\def\gobble#1{}
\renewcommand\DeleteFile[1]{}
\usepackage{xparse}
\ExplSyntaxOn
\box_new:N \l_fvrb_box
\tl_new:N \l_fvrb_tl
\RenewDocumentCommand \FancyVerbFormatLine { m }
{
\hbox_set:Nn \l_fvrb_box { #1 }
\dim_compare:nNnTF { \box_wd:N \l_fvrb_box }>{ \linewidth }
{
\tl_set:Nn \l_fvrb_tl { #1 }
\fvrb_use_tl:N \l_fvrb_tl
}
{%box fits
\box_use:N \l_fvrb_box
}
}
\cs_new:Npn \fvrb_use_tl:N #1
{
\group_begin:
\null\hfill\vbox_set:Nn \l_fvrb_box
{\hsize=\linewidth
\renewcommand\thelinenumber
{
\ifnum\value{linenumber}=1\relax\else
$\rightarrow$
\fi
}
\begin{internallinenumbers}
\advance\hsize by -2em
\hspace*{-2em}\tl_use:N #1
\end{internallinenumbers}
}
\box_use:N \l_fvrb_box
\group_end:
}
\ExplSyntaxOff
\definecolor{mintedbg}{RGB}{250,255,250}
\usepackage{etoolbox}
\BeforeBeginEnvironment{minted}{%
\begin{tcolorbox}[
width=\linewidth,
enlarge top by=3pt,
enlarge bottom by=3pt,
enlarge left by=3pt,
enlarge right by=3pt,
frame hidden,boxrule=0pt,
top=1mm,
bottom=1mm,
colframe=green!30!black,
colbacktitle=green!50!yellow,
coltitle=black,
colback=mintedbg,
freelance,
arc=0pt,
outer arc=0pt,
boxrule=0pt,
frame code={
\draw[blue!87!green!13,line width=0.8pt]
([xshift=-0.5pt]frame.north west) -- ([xshift=-0.5pt]frame.south west);
\draw[blue!70!green!30,line width=0.9pt]
([xshift=-3pt]frame.north west) -- ([xshift=-3pt]frame.south west);
\draw[blue!53!green!47,line width=0.8pt]
([xshift=-5.5pt]frame.north west) -- ([xshift=-5.5pt]frame.south west);
}
]}
\AfterEndEnvironment{minted}{\end{tcolorbox}}%
\begin{document}
\begin{minted}{latex}
%Preamble
\usepackage[]{minted}
\usepackage[fancyvrb=true]{listings}
\usepackage{tcolorbox}
\usepackage{etoolbox}
\BeforeBeginEnvironment {minted} { \begin{tcolorbox} } \AfterEndEnvironment {minted} { \end{tcolorbox} }%
\usepackage{lipsum}
\end{minted}
\end{document}
结果:
我从 改为enhanced
,freelance
并习惯frame code
只在左侧绘制线条(我还将arc
和设置outer arc
为);根据需要0pt
调整命令的设置。\draw