![整个逐字部分均采用斜体字体](https://linux22.com/image/320688/%E6%95%B4%E4%B8%AA%E9%80%90%E5%AD%97%E9%83%A8%E5%88%86%E5%9D%87%E9%87%87%E7%94%A8%E6%96%9C%E4%BD%93%E5%AD%97%E4%BD%93.png)
如何在 verbatim 环境中将字体格式更改为斜体?
\documentclass[a4paper]{article}
\begin{document}
\begin{Verbatim}
@book{book;
title = {title};
author = {author};
volume = {1};
year = {2015};
publisher = {x}
}
\end{Verbatim}
\end{document}
答案1
在当地,
\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
\begin{Verbatim}[fontshape=it]
@book{book,
title = {title},
author = {author},
volume = {1},
year = {2015},
publisher = {x}
}
\end{Verbatim}
\end{document}
从全球来看,
\documentclass{article}
\usepackage{fancyvrb}
\fvset{fontshape=it}
\begin{document}
\begin{Verbatim}
@book{book,
title = {title},
author = {author},
volume = {1},
year = {2015},
publisher = {x}
}
\end{Verbatim}
\end{document}
这将给出斜体等宽字体:
对于标准verbatim
环境,重新定义\verbatim@font
:
\documentclass{article}
\makeatletter
\renewcommand\verbatim@font{\itshape}
\makeatother
\begin{document}
\begin{verbatim}
@book{book,
title = {title},
author = {author},
volume = {1},
year = {2015},
publisher = {x}
}
\end{verbatim}
\end{document}
答案2
另一个选项是verbatimbox
允许在可选参数中提供格式化宏的包。它具有环境verbnobox
,其功能类似于verbatim
,以及verbbox
将逐字内容放入已保存框的环境,该框稍后可以使用内联输出,theverbbox
此处显示在内\fbox
。
\documentclass[a4paper]{article}
\usepackage{verbatimbox}
\begin{document}
\noindent Normal Size, italic shape verbatim text
\begin{verbnobox}[\itshape]
@book{book;
title = {title};
author = {author};
volume = {1};
year = {2015};
publisher = {x}
}
\end{verbnobox}
\begin{verbbox}[\itshape\tiny]
@book{book;
title = {title};
author = {author};
volume = {1};
year = {2015};
publisher = {x}
}
\end{verbbox}
Here is \fbox{\theverbbox} inline.
\end{document}
宏的可选参数verbatimbox
实际上非常可编程。此处,“程序”存储在 中\tmp
。
\documentclass[a4paper]{article}
\usepackage{verbatimbox}
\begin{document}
\def\tmp{\ifnum\theVerbboxLineNo=2\itshape\else%
\ifnum\theVerbboxLineNo=4\leavevmode\llap{$\bullet$ }\fi\fi}
\begin{verbnobox}[\tmp]
@book{book;
title = {title};
author = {author};
volume = {1};
year = {2015};
publisher = {x}
}
\end{verbnobox}
\end{document}