我认为 Drew Neil(Vimcasts.org名声)使用一些 TeX 排版引擎(XeLaTeX?)排版了他优秀的书,实用 Vim.请参见下面的屏幕截图。
我真的很喜欢他的“小费盒”在正文中脱颖而出并吸引读者注意力的方式,但又不会太过浮夸或“直白”。你认为他使用什么包装来制作这些花哨的盒子(尤其是“小费 2”部分)?该mdframed
包装似乎没有提供这种级别的定制。该tcolorbox
包装更有可能是候选者,但我没有在手册中发现任何类似于下面显示的盒子...
您认为作者是如何生成这些框的?
答案1
mdframed
和都很tcolorbox
强大,并提供高度可定制的盒子;下面我展示了使用每个包实现所需盒子的一些选项。
由于这两个软件包都提供了从头开始设计框架的可能性以及一个简单的预定义坐标系统,因此可能性是无穷无尽的。
对于每个包我都会展示两个版本:一个更适合于框不包含分页符的情况,另一个更适合于框内可以出现分页符的情况。
首先,让我们考虑使用tcolorbox
如果框内没有分页符,则为适当:
\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\newtcolorbox[auto counter]{mybox}{
freelance,
colback=white,
frame code={},
interior titled code={
\fill[rounded corners=8pt,gray!30]
(title.south west) --
(title.south) --
([yshift=20pt]title.south) --
([yshift=20pt,xshift=4cm]title.south) --
([xshift=4cm]title.south) --
(title.south east) {[sharp corners] --
([yshift=-6pt]title.south east) --
([yshift=-6pt]title.south west) } -- cycle;
\draw[rounded corners=8pt,gray,line width=1pt]
(title.west|-frame.south west) --
(title.south west) --
(title.south) --
([yshift=20pt]title.south) --
([yshift=20pt,xshift=4cm]title.south) --
([xshift=4cm]title.south) --
(title.south east) --
(title.east|-frame.south east) --
cycle;
\node at ([xshift=2cm,yshift=4pt,anchor=south]title.south)
{\sffamily\Large Tip~\thetcbcounter};
},
title={\mbox{}},
top=12pt,
fontupper=\sffamily\Large,
oversize=0.5cm,
before={\vskip24pt\par\noindent},
after={\par\vskip12pt}
}
\begin{document}
\lipsum[2]
\begin{mybox}
Don't Repeat Yourself
\end{mybox}
\lipsum[2]
\begin{mybox}
Don't Repeat Yourself
\end{mybox}
\end{document}
现在,允许分页的版本:
\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\newtcolorbox[auto counter]{mybox}{
breakable,
freelance,
colback=white,
frame code={},
overlay unbroken={
\fill[rounded corners=8pt,gray!30]
(title.south west) --
(title.south) --
([yshift=20pt]title.south) --
([yshift=20pt,xshift=4cm]title.south) --
([xshift=4cm]title.south) --
(title.south east) {[sharp corners] --
([yshift=-6pt]title.south east) --
([yshift=-6pt]title.south west) } -- cycle;
\draw[rounded corners=8pt,gray,line width=1pt]
(title.west|-frame.south west) --
(title.south west) --
(title.south) --
([yshift=20pt]title.south) --
([yshift=20pt,xshift=4cm]title.south) --
([xshift=4cm]title.south) --
(title.south east) --
(title.east|-frame.south east) --
cycle;
\node at ([xshift=2cm,yshift=4pt,font=]title.south)
{\sffamily\Large Tip~\thetcbcounter};
},
overlay first={
\fill[rounded corners=8pt,gray!30]
(title.south west) --
(title.south) --
([yshift=20pt]title.south) --
([yshift=20pt,xshift=4cm]title.south) --
([xshift=4cm]title.south) --
(title.south east) {[sharp corners] --
([yshift=-6pt]title.south east) --
([yshift=-6pt]title.south west) } -- cycle;
\draw[rounded corners=8pt,gray,line width=1pt]
(title.west|-frame.south) --
(title.south west) --
(title.south) --
([yshift=20pt]title.south) --
([yshift=20pt,xshift=4cm]title.south) --
([xshift=4cm]title.south) --
(title.south east) --
(title.south east|-frame.south);
\node at ([xshift=2cm,yshift=4pt,font=]title.south)
{\sffamily\Large Tip~\thetcbcounter};
},
overlay middle={
\draw[rounded corners=8pt,gray,line width=1pt]
(title.west|-frame.south) --
(title.west|-frame.north);
\draw[rounded corners=8pt,gray,line width=1pt]
(title.east|-frame.south) --
(title.east|-frame.north);
},
overlay last={
\draw[rounded corners=8pt,gray,line width=1pt]
(title.west|-frame.north) --
(title.west|-frame.south) --
(title.east|-frame.south) --
(title.east|-frame.north);
},
title={\mbox{}},
top=12pt,
fontupper=\sffamily\Large,
oversize=0.5cm,
before={\vskip28pt\par\noindent},
after={\par\vskip12pt},
}
\begin{document}
\lipsum[2]
\begin{mybox}
\lipsum[4-6]
\end{mybox}
\lipsum[2]
\end{document}
并使用mdframed
;首先是适合无分页符的版本(如果使用此版本出现分页符,则框会断开,但不绘制框架)。分页符的版本可在本答案的末尾找到。
\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}
\usepackage{lipsum}
\newcounter{tip}
\newmdenv[
hidealllines=true,
innertopmargin=14pt,
innerbottommargin=8pt,
skipabove=10pt,
font=\sffamily\Large,
leftmargin=-0.5cm,
rightmargin=-0.5cm,
singleextra={
\coordinate (aux) at ( $ (O)!0.5!(P) $ );
\fill[rounded corners=8pt,line width=1pt,gray!30]
(O|-P) --
(aux|-P) --
([yshift=20pt]aux|-P) --
([yshift=20pt,xshift=4cm]aux|-P) --
([xshift=4cm]aux|-P) --
(P) {[sharp corners] --
([yshift=-6pt]P) --
([yshift=-6pt]O|-P) } -- cycle;
\draw[rounded corners=8pt,line width=1pt,gray]
(O|-P) --
(aux|-P) --
([yshift=20pt]aux|-P) --
([yshift=20pt,xshift=4cm]aux|-P) --
([xshift=4cm]aux|-P) --
(P) --
(P|-O) --
(O) -- cycle;
\node at ([xshift=2cm,yshift=6pt]aux|-P)
{\refstepcounter{tip}\sffamily\Large Tip~\thetip} ;
},
]{mybox}
\begin{document}
\lipsum[2]
\begin{mybox}
Don't Repeat Yourself
\end{mybox}
\lipsum[2]
\begin{mybox}
Don't Repeat Yourself
\end{mybox}
\end{document}
mdframed
这是用于分页符可能出现在框内的情况的选项:
\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}
\usepackage{lipsum}
\newcounter{tip}
\newmdenv[
hidealllines=true,
innertopmargin=16pt,
innerbottommargin=10pt,
font=\sffamily\Large,
leftmargin=-0.5cm,
rightmargin=-0.5cm,
skipabove=35pt,
skipbelow=15pt,
singleextra={
\coordinate (aux) at ( $ (O)!0.5!(P) $ );
\fill[rounded corners=8pt,line width=1pt,gray!30]
(O|-P) --
(aux|-P) --
([yshift=20pt]aux|-P) --
([yshift=20pt,xshift=4cm]aux|-P) --
([xshift=4cm]aux|-P) --
(P) {[sharp corners] --
([yshift=-6pt]P) --
([yshift=-6pt]O|-P) } -- cycle;
\draw[rounded corners=8pt,line width=1pt,gray]
(O|-P) --
(aux|-P) --
([yshift=20pt]aux|-P) --
([yshift=20pt,xshift=4cm]aux|-P) --
([xshift=4cm]aux|-P) --
(P) --
(P|-O) --
(O) -- cycle;
\node at ([xshift=2cm,yshift=6pt]aux|-P)
{\refstepcounter{tip}\sffamily\Large Tip~\thetip} ;
},
firstextra={
\coordinate (aux) at ( $ (O)!0.5!(P|-O) $ );
\fill[rounded corners=8pt,line width=1pt,gray!30,overlay]
(O|-P) --
(aux|-P) --
([yshift=20pt]aux|-P) --
([yshift=20pt,xshift=4cm]aux|-P) --
([xshift=4cm]aux|-P) --
(P) {[sharp corners] --
([yshift=-6pt]P) --
([yshift=-6pt]O|-P) } -- cycle;
\draw[rounded corners=8pt,line width=1pt,gray,overlay]
(O) --
(O|-P) --
(aux|-P) --
([yshift=20pt]aux|-P) --
([yshift=20pt,xshift=4cm]aux|-P) --
([xshift=4cm]aux|-P) --
(P) --
(P|-O);
\node[overlay] at ([xshift=2cm,yshift=6pt]aux|-P)
{\refstepcounter{tip}\sffamily\Large Tip~\thetip} ;
},
middleextra={
\draw[rounded corners=8pt,line width=1pt,gray,overlay]
(O|-P) --
(O);
\draw[rounded corners=8pt,line width=1pt,gray,overlay]
(P) --
(P|-O);
},
secondextra={
\coordinate (aux) at ( $ (O)!0.5!(P|-O) $ );
\draw[rounded corners=8pt,line width=1pt,gray,overlay]
(O|-P) --
(O) --
(P|-O) --
(P);
},
]{mybox}
\begin{document}
\lipsum[2]
\begin{mybox}
\lipsum[4-6]
\end{mybox}
\lipsum[2]
\end{document}