自动逐字换行文本

自动逐字换行文本

在 tex 环境中,当我尝试使用 verbatim 包中的 verbatim 函数时,有时行中较长的文本会被截断。我该如何调整文本大小以适合行或自动将文本延伸到下一行以保留所有文本。例如,我有以下文本:

    \begin{verbatim}
        C **  RAINCVT   =CONVERTS RAIN TO UNITS OF M/SEC , inch/day=0.0254m/86400s=2.94E-7m/s, inch/h=7.05556E-6m/s
C **  EVAPCVT   =CONVERTS EVAP TO UNITS OF M/SEC, IF EVAPCVT<0 EVAP IS INTERNALLY COMPUTED
C **  SOLRCVT   =CONVERTS SOLAR SW RADIATION TO JOULES/S/SQ METER (Watts/m^2)
    \end{verbatim}

在我的输出中,第一行没有显示所有文本。如果有人能告诉我如何限制浮动逐字,我将不胜感激?在表格中使用[h]末尾的标签可以固定表格的位置,但对逐字似乎不起作用。

答案1

标准verbatim环境非常基础。要实现自动换行,请使用listings包及其breaklines=true选项:

\documentclass[11pt]{article}
\usepackage{listings}
\lstset{
basicstyle=\small\ttfamily,
columns=flexible,
breaklines=true
}

\begin{document}

With the standard \texttt{verbatim} environment:
\begin{verbatim}
        C **  RAINCVT   =CONVERTS RAIN TO UNITS OF M/SEC , inch/day=0.0254m/86400s=2.94E-7m/s, inch/h=7.05556E-6m/s
C **  EVAPCVT   =CONVERTS EVAP TO UNITS OF M/SEC, IF EVAPCVT<0 EVAP IS INTERNALLY COMPUTED
C **  SOLRCVT   =CONVERTS SOLAR SW RADIATION TO JOULES/S/SQ METER (Watts/m^2)
    \end{verbatim}

With the \texttt{lstlisting} environment and \texttt{breaklines=true}:
\begin{lstlisting}
        C **  RAINCVT   =CONVERTS RAIN TO UNITS OF M/SEC , inch/day=0.0254m/86400s=2.94E-7m/s, inch/h=7.05556E-6m/s
C **  EVAPCVT   =CONVERTS EVAP TO UNITS OF M/SEC, IF EVAPCVT<0 EVAP IS INTERNALLY COMPUTED
C **  SOLRCVT   =CONVERTS SOLAR SW RADIATION TO JOULES/S/SQ METER (Watts/m^2)
    \end{lstlisting}

\end{document}

在此处输入图片描述

相关内容