我在定义新环境时尝试放置 scalebox{.2},但它未被应用:
\documentclass[10pt,a5paper,twoside]{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage[showframe,pass]{geometry}
\usepackage{graphicx}
\makeatletter
\newenvironment{myenvironment}[0]
{scalebox{.2}\{myenvironment start\par\verbatim}
{\endverbatim\endgraf myenvironment end\}}
\makeatother
\begin{document}
\begin{myenvironment}
test
\end{myenvironment}
\end{document}
如何在我的环境中使用 \scalebox?
答案1
使用该包有两种方法可以实现此目的verbatimbox
。请注意,第二种方法需要可缩放字体,这就是我添加该lmodern
包的原因。
\documentclass[10pt,a5paper,twoside]{memoir}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage[showframe,pass]{geometry}
\usepackage{graphicx,verbatimbox}
\begin{document}
\begin{verbbox}
test
of my
\%\@# verbatim stuff
\end{verbbox}
\noindent\scalebox{.2}{\theverbbox}
versus normal size
\begin{verbnobox}[\fontsize{2pt}{2.5pt}\selectfont]
test
of my
\%\@# verbatim stuff
\end{verbnobox}
Back to normal
\end{document}
答案2
答案3
非常类似于列规范运算符中的 \scalebox >{...},但是verbatim
也不能放在里面,所以你需要按照建议的hbox
原始setbox
https://tex.stackexchange.com/a/41707/250119:
%! TEX program = lualatex
\documentclass[10pt,a5paper,twoside]{memoir}
\usepackage{graphicx}
\newbox\mybox
\makeatletter
\ExplSyntaxOn
\newenvironment{myenvironment}[0]
{
\setbox\mybox\vbox\bgroup
myenvironment~start
\par
\verbatim}
{
\endverbatim
\endgraf myenvironment~end
\egroup
\scalebox{.2}{\box\mybox}}
\ExplSyntaxOff
\makeatother
\begin{document}
\begin{myenvironment}
test
\end{myenvironment}
\end{document}
我更喜欢\ExplSyntaxOn
,但你也可以%
每行。
答案4
如果你想要逐字模式,你可以使用fancyvrb
\documentclass[10pt,a5paper,twoside]{memoir}
\usepackage[T1]{fontenc}
\usepackage[brazil]{babel}
\usepackage{fancyvrb}
\usepackage{graphicx}
\usepackage[showframe,pass]{geometry}
\makeatletter
\newsavebox{\mybox}
\newenvironment{myenvironment}
{\VerbatimEnvironment\begin{lrbox}{\mybox}\begin{BVerbatim}}
{%
\end{BVerbatim}\end{lrbox}%
\par\smallskip\hrule\smallskip % or whatever you want at the top
\noindent\scalebox{.2}{\usebox{\mybox}}%
\par\smallskip\hrule\smallskip % or whatever you want at the bottom
\@endpetrue
}
\makeatother
\begin{document}
Some text before the scaled verbatim
some text before the scaled verbatim
some text before the scaled verbatim
\begin{myenvironment}
test
\end{myenvironment}
Some text after the scaled verbatim
some text after the scaled verbatim
some text after the scaled verbatim
\end{document}