我想做一个这样的盒子
但没有出现粗体文字。
編輯:
\documentclass{article}
\usepackage{listings,xcolor,etoolbox,lmodern}
\definecolor{verbgray}{gray}{0.9}
\newcommand*\prompt{}% empty default
\lstnewenvironment{sh}{%
% redefine bash prompt:
\def\prompt{user@linux:\textasciitilde\$\space}%
\lstset{backgroundcolor=\color{verbgray},
frame=single,
framerule=1pt,
basicstyle=\ttfamily,
columns=fullflexible,
escapechar=@
}%
}{}
\begin{document}
\begin{sh}
@\prompt\space\textbf{date}@
Thu Oct 25 13:51:54 EDT 2007
\end{sh}
\end{document}
答案1
以下是您所写内容的稍加修改的版本:
\documentclass{article}
\usepackage{lmodern}
\usepackage{listings,xcolor,etoolbox}
\definecolor{verbgray}{gray}{0.9}
\newcommand*\prompt{}% empty default
\lstnewenvironment{sh}{%
% redefine bash prompt:
\def\prompt{user@linux:\textasciitilde\$\space}%
\lstset{backgroundcolor=\color{verbgray},
frame=single,
framerule=1pt,
basicstyle=\ttfamily,
columns=fullflexible,
escapechar=@
}%
}{}
% patch \lst@NewLine:
\makeatletter
\patchcmd\lst@NewLine
{\hbox{}}% search
{\hbox{}\prompt}% replace
{}% success
{}% failure
\makeatother
\begin{document}
\begin{sh}
@\textbf{date}@
Thu Oct 25 13:51:54 EDT 2007
\end{sh}
\end{document}
您需要在创建时允许使用粗体字体ttfamily
。因此加载
\usepackage{lmodern}