我使用以下命令在报告中间引入 bash 脚本文本:
\newcommand{\shellcmd}[1]{\\\indent\indent\texttt{\footnotesize\# #1}\\}
\begin{document}
\noindent Consider the following command:
\shellcmd{apt-get --purge remove rubygems}
This removes the \texttt{rubygems} package.
\end{document}
问题是,当行太长时,它会在页面的右角断开。我该如何重新定义它,以便行与剩余的文本对齐?
先感谢您,
答案1
这是一个tcolorbox
(tcblisting)方法:
\documentclass{article}
%\newcommand{\shellcmd}[1]{\\\indent\indent\texttt{\footnotesize\# #1}\\}
\usepackage[most]{tcolorbox}
\begin{document}
\noindent Consider the following command:
\begin{tcblisting}{arc=0pt,auto outer arc,listing options={language={bash}},listing only,every listing line={\textcolor{red}{\small\ttfamily\bfseries username \$>}}}
apt-get --purge remove rubygems
apt-get --purge remove rubygems ; apt-get --purge remove rubygems ; apt-get --purge remove rubygems
\end{tcblisting}
This removes the \texttt{rubygems} package.
\end{document}