我有以下用于显示代码的环境:
效果很好,但现在我遇到了一个问题,即 -- 在该环境中变成了一个短划线。例如:
我也试过了{-}{-}
,-{}-
但里面的 Verbatim{}
没有翻译。有什么办法可以正确解决这个问题吗?
\documentclass[11pt, twocolumn, landscape]{article} % use "amsart" instead of "article" for AMSLaTeX format
\usepackage[a4paper]{geometry} % See geometry.pdf to learn the layout options. There are lots.
\usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{color}
\usepackage{verbatim}
\usepackage{frame}
\usepackage{fancybox,calc}
\usepackage[svgnames]{xcolor}
\usepackage{fullpage}
\setlength{\columnsep}{4em}
\newenvironment{code}{\VerbatimEnvironment%
\noindent
% {\columnwidth-\leftmargin-\rightmargin-2\fboxsep-2\fboxrule-4pt}
\begin{Sbox}
\begin{minipage}{\linewidth-2\fboxsep-2\fboxrule-4pt}
\color{DarkBlue}\begin{Verbatim}
}{%
\end{Verbatim}
\end{minipage}
\end{Sbox}
\fcolorbox{DarkBlue}{Orange}{\TheSbox}
}
\begin{document}
\pagenumbering{gobble}
\begin{code}
git config --global user.name "Max Mustermann"
git config --global user.email "[email protected]"
\end{code}
\end{document}
答案1
问题在于和都fancyvrb
定义fancybox
了Verbatim
环境。
定义的fancybox
有这个问题,而 定义的fancyvrb
没有这个问题。
因此,加载fancyvrb
后fancybox
解决了问题,即替换行
\usepackage{fancyvrb,fancybox,calc}
和
\usepackage{fancybox,fancyvrb,calc}
完整代码:
\documentclass[11pt, twocolumn, landscape]{article} % use "amsart" instead of "article" for AMSLaTeX format
\usepackage[a4paper]{geometry} % See geometry.pdf to learn the layout options. There are lots.
\usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{color}
\usepackage{verbatim}
\usepackage{frame}
\usepackage{fancybox,fancyvrb,calc}
\usepackage[svgnames]{xcolor}
\usepackage{fullpage}
\setlength{\columnsep}{4em}
\newenvironment{code}{\VerbatimEnvironment%
\noindent
% {\columnwidth-\leftmargin-\rightmargin-2\fboxsep-2\fboxrule-4pt}
\begin{Sbox}
\begin{minipage}{\linewidth-2\fboxsep-2\fboxrule-4pt}
\color{DarkBlue}\begin{Verbatim}
}{%
\end{Verbatim}
\end{minipage}
\end{Sbox}%
\fcolorbox{DarkBlue}{Orange}{\TheSbox}
}
\begin{document}
\pagenumbering{gobble}
\begin{code}
git config --global user.name "Max Mustermann"
git config --global user.email "[email protected]"
\end{code}
\end{document}
输出:
PS 我后面添加了一个%
字符\end{Sbox}
以避免出现虚假空格。