我正在尝试将逐字片段与其输出对齐。考虑这个 MWE:
\documentclass{article}
\usepackage{lmodern}
\usepackage{fancyvrb}
\DefineVerbatimEnvironment{IVerbatim}{Verbatim}{xleftmargin=2em, gobble=2}
\begin{document}
Here is some verbatim text, indented by 2em:
\begin{IVerbatim}
Do \textit{something}!
\end{IVerbatim}
Now here is its result, indented by 2em:
\begin{quote}
Do \textit{something}!
\end{quote}
How can I get them to align?
\end{document}
quote
&环境都IVerbatim
缩进 2em;问题是 LMRoman 字体的 em 比 LMMono 字体的 em 宽。
(更正:正如接受的答案中提到的,quote
环境实际上缩进了 2.5 em。)
我如何将段落的缩进设置IVerbatim
为罗马字体的 2em?这需要我可以插入到行中xleftmargin=〈
something
〉
。
答案1
四边形宽度 (= ) 的值1em
由 控制\fontdimen6
。根据article.cls
,环境内部使用的缩进quote
是2.5em
,因此您可以这样说:
\documentclass{article}
\usepackage{lmodern}
\usepackage{fancyvrb}
\usepackage{tikz}
\usetikzlibrary{calc}
\DefineVerbatimEnvironment{IVerbatim}{Verbatim}{xleftmargin=2.5\mylen, gobble=2}
\newlength\mylen
\begin{document}
\setlength\mylen{\fontdimen6\font}
The value of \texttt{1em} is: \the\mylen
Here is some verbatim text, indented by 2.5em:
\begin{IVerbatim}
Do \textit{something}!
\end{IVerbatim}
Now here is its result, indented by 2.5em:
\begin{quote}
Do \textit{something}!
\end{quote}
\tikz[remember picture,overlay] \draw[blue] ( $ (current page.north west) + (159.5pt,0) $ )-- ( $ (current page.south west)+ (159.5pt,0) $ );
\end{document}
我只是为了可视化目的添加了垂直规则:
获取值的另一种方法1em
是测量空间的长度\quad
:
\settowidth\mylen{\quad}\the\mmylen
这是一个简单的文档,显示了根据字体的字体系列而变化的四边形宽度的不同值lmodern
:
\documentclass{article}
\usepackage{lmodern}
\setlength\parindent{0pt}
\newcommand\QuadWd{%
The value of 1em is \the\fontdimen6\font\par}
\begin{document}
\QuadWd
{\ttfamily\QuadWd}
{\sffamily\QuadWd}
\end{document}