您好,我正在尝试设置脚本框的样式。
到目前为止我已经开始
\begin{script*} >> help \end{script*}
工作和展示
我希望最终版本看起来与这张图片有些相似
并有第二条评论将使用或多或少相同的环境
例如
我确信可以用乳胶来完成,但我没有足够的经验和知识。
任何帮助都将不胜感激谢谢!
[更新] 这是我决定保留的最终版本,它使用 tikz 和 mdframed
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{listings}
\definecolor{topBlue}{RGB}{42,93,147}
\definecolor{bottomBlue}{RGB}{10,60,113}
\definecolor{sideline}{RGB}{235,235,237}
\definecolor{frameBlue}{RGB}{17,74,135}
\usepackage{tikz}
\usepackage[framemethod=TikZ]{mdframed}
\usetikzlibrary{calc,shapes.geometric}
\newcommand{\triangcirc}{\tikz{
\node[draw=frameBlue,inner ysep=4pt,
color=frameBlue,
top color=topBlue,
bottom color=bottomBlue,
text=white,
align=flush left,
font=\textbf\textsf,
text width=\textwidth] (a) {Command Window};
\node[circle,white,draw,inner sep=3pt] (c) at ([xshift=-3mm]a.east) {};
\node[isosceles triangle,
white,
fill,
rotate=-90,
anchor=apex,
isosceles triangle apex angle=60,
inner sep=1.2pt] (t) at ([yshift=1.5pt]c.south) {};}}
\mdfdefinestyle{commandline}
{leftmargin=0pt, rightmargin=0pt,innerleftmargin=-0.5pt,innerrightmargin=7.5pt,
middlelinecolor=frameBlue,
middlelinewidth=1.2pt,
frametitlerule=false,
backgroundcolor=white,
frametitle={\triangcirc},
frametitleaboveskip=-0.5pt,
frametitlebelowskip=0pt,
singleextra={\draw[sideline,line width=12pt]
($(O)+(7pt,1pt)$) -- ($(O|-P)+(7pt,-\mdfframetitleboxtotalheight)-(0,1pt)$);
\node[inner sep=0pt,color=black]at ($(O)+(7pt,9pt)$) {$\scriptstyle f\!x$}; }
}
\lstnewenvironment{script} {\lstset{language=Matlab,xleftmargin=5mm,basicstyle=\footnotesize,,breaklines=true,aboveskip=-2pt,belowskip=0pt}} {}
\surroundwithmdframed[style=commandline]{script}
\begin{document}
\begin{script}
>> help sin
sin Sine of argument in radians.
sin(X) is the sine of the elements of X.
See also asin, sind.
Overloaded methods:
sdpvar/sin
codistributed/sin
gpuArray/sin
Reference page in Help browser
doc sin
>>
\end{script}
\end{document}
并感谢两位的回答!
答案1
这是使用的版本mdframed
。
经过修改的版本
我已经更新了答案,包括了之前答案中缺少的灰色条,并且我已经通过使用消除了对 Apple 字体的依赖打击乐器圆圈三角形的代码。由于mdframed
允许跨页中断,因此此解决方案比将代码放在 TikZ 节点中的解决方案稍微灵活一些。
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\definecolor{DarkBlue}{rgb}{.11,.23,.60}
\usepackage[framemethod=TikZ]{mdframed}
\usetikzlibrary{calc,shapes.geometric}
\newcommand{\triangcirc}{\tikz{
\node[circle,white,draw,inner sep=3pt] (c) {};
\node[isosceles triangle,
white,
fill,
rotate=-90,
anchor=apex,
isosceles triangle apex angle=60,
inner sep=1.5pt] (t) at ([yshift=0.5pt]c.south) {};}}
\mdfdefinestyle{commandline}
{leftmargin=5pt, rightmargin=10pt,innerleftmargin=15pt,
middlelinecolor=DarkBlue,
middlelinewidth=2pt,
backgroundcolor=white,
frametitle={Command Window\hfill\triangcirc},
frametitlefont={\normalfont\sffamily\color{white}\hspace{-1.25em}},
frametitlebackgroundcolor=DarkBlue,
singleextra={\draw[black!20,line width=12pt] node[inner sep=0pt,color=black]
at ($(O)+(7pt,9pt)$) {$\scriptstyle f\!x$}
($(O)+(7pt,1pt)$) -- ($(O|-P)+(7pt,-\mdfframetitleboxtotalheight-1pt)$);}}
\newmdenv[style=commandline]{cmdline}
\usepackage{listings}
\lstset{language=Matlab,basicstyle=\tiny\ttfamily,breaklines=true}
\begin{document}
\begin{cmdline}
\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
>> help sin
sin Sine of argument in radians.
sin(X) is the sine of the elements of X.
See also asin, sind.
Overloaded methods:
sdpvar/sin
codistributed/sin
gpuArray/sin
Reference page in Help browser
doc sin
>>
\end{lstlisting}%
\end{cmdline}
\end{document}
以下代码通过定义环境来简化完整的方法,script
从而产生所需的输出:
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\definecolor{DarkBlue}{rgb}{.11,.23,.60}
\usepackage[framemethod=TikZ]{mdframed}
\usetikzlibrary{calc,shapes.geometric}
\newcommand{\triangcirc}{\tikz{
\node[circle,white,draw,inner sep=3pt] (c) {};
\node[isosceles triangle,
white,
fill,
rotate=-90,
anchor=apex,
isosceles triangle apex angle=60,
inner sep=1.5pt] (t) at ([yshift=0.5pt]c.south) {};}}
\mdfdefinestyle{commandline}
{leftmargin=5pt, rightmargin=10pt,innerleftmargin=15pt,
middlelinecolor=DarkBlue,
middlelinewidth=2pt,
frametitlerule=false,
backgroundcolor=black!10!white,
frametitle={Command Window\hfill\triangcirc},
frametitlefont={\normalfont\sffamily\color{white}\hspace{-1.25em}},
frametitlebackgroundcolor=DarkBlue,
singleextra={\draw[black!20,line width=12pt]
($(O)+(7pt,1pt)$) -- ($(O|-P)+(7pt,-\mdfframetitleboxtotalheight)-(0,1pt)$);
\node[inner sep=0pt,color=black]at ($(O)+(7pt,9pt)$) {$\scriptstyle f\!x$}; }
}
\usepackage{listings}
\lstnewenvironment{script} {\lstset{language=Matlab,basicstyle=\tiny\ttfamily,breaklines=true,aboveskip=0pt,belowskip=0pt}} {}
\surroundwithmdframed[style=commandline]{script}
\begin{document}
\begin{script}
>> help sin
sin Sine of argument in radians.
sin(X) is the sine of the elements of X.
See also asin, sind.
Overloaded methods:
sdpvar/sin
codistributed/sin
gpuArray/sin
Reference page in Help browser
doc sin
>>
\end{script}
\end{document}
答案2
如果 mdframed 没有直接支持此功能(但我怀疑它不支持),只需快速操作即可。基本功能是存在的,例如根据垂直尺寸缩小通孔等。但我没有对其进行广泛的测试,而且我懒得处理 $fx$ 部分的三角形。也许更好的字体会让它看起来更漂亮。
\documentclass{article}
\usepackage{tikz,listings,amssymb}
\lstset{language=Matlab,basicstyle=\tiny\ttfamily,breaklines=true}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[draw,inner ysep=3pt,
top color=blue!60!black,
bottom color=blue,
text=white,
align=flush left,
font=\tiny\ttfamily,
text width=\textwidth] (a) {Command Window};
\node[circle,white,draw,inner sep=1.9pt] (c) at ([xshift=-3mm]a.east) {};
\node[isosceles triangle,
white,
fill,
rotate=-90,
anchor=apex,
isosceles triangle apex angle=60,
inner sep=0.8pt] (t) at ([yshift=0.5pt]c.south) {};
\node[
anchor=north west,
minimum width=\textwidth-3mm,
align=flush left,
font=\tiny\ttfamily,
text width=\textwidth-3mm,
inner sep=0
] (l) at ([xshift=3mm]a.south west)
{%
\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
>> help sin
sin Sine of argument in radians.
sin(X) is the sine of the elements of X.
See also asin, sind.
Overloaded methods:
sdpvar/sin
codistributed/sin
gpuArray/sin
Reference page in Help browser
doc sin
>>
\end{lstlisting}%
};
\filldraw[fill=blue!10,draw=white] ([yshift=-0.3pt]a.south west) rectangle (l.south west);
\draw ([xshift=0.3pt]a.south west) rectangle ([xshift=2mm+0.7pt]l.south east);
\node[anchor=south east,inner xsep=0.5pt,inner ysep=1pt] (f) at (l.south west) {$\scriptstyle f\!x$};
\end{tikzpicture}
\end{document}