如何处理 LaTeX 中的 % 字符?

如何处理 LaTeX 中的 % 字符?

我正在研究特殊字符处理,我的文本中有一个 % 特殊字符,该字符被视为注释,之后的任何内容都不会打印。我按照上一个帖子中的建议使用了动词,但仍然有问题。

如何处理 LaTeX 中的特殊字符?

下面是我的代码。

\documentclass[11pt,table,a4paper]{article}
\usepackage{array,ragged2e}
\usepackage[scaled]{uarial}
\usepackage[T1]{fontenc}
\begin{document}
\begin{minipage}{0.3\linewidth}
\def\verbatim@font{\normalfont\ua1} 
This is my sample text for checking % character. I found whereever there   is     % character it is treated as comment and nothing gets printed after this. How can i fix this pblm. I m using verb still getting same pblm. pls help me how can i fix this pblm.
\end{minipage}
\end{document}

答案1

要排版逐字材料,您需要使用verbatim环境(在代码片段中,您只为逐字材料选择了字体)并手动引入换行符(我注释掉了一些行,因为我没有uarial.sty):

\documentclass[11pt,table,a4paper]{article}
\usepackage{array,ragged2e}
%\usepackage[scaled]{uarial}
\usepackage[T1]{fontenc}

\makeatletter
%\def\verbatim@font{\normalfont\ua1} 
\makeatother

\begin{document}

\begin{verbatim}
This is my sample text for checking % character. I found 
whereever there  is  % character it is treated as comment 
and nothing gets printed after this. How can i fix this pblm. 
I m using verb still getting same pblm. pls help me how 
can i fix this pblm.
\end{verbatim}

\end{document}

在此处输入图片描述

fancyvrb软件包提供了更多的可能性和增强的逐字环境/命令;该listings软件包扩展了更多的可能性。

如果您需要排版百分比字符,请使用\%

\documentclass[11pt,table,a4paper]{article}
\usepackage{array,ragged2e}
%\usepackage[scaled]{uarial}
\usepackage[T1]{fontenc}

\begin{document}
\begin{minipage}{0.3\linewidth}
This is my sample text for checking \% character. I found whereever there   is   \% character it is treated as comment and nothing gets printed after this. How can i fix this pblm. I m using verb still getting same pblm. pls help me how can i fix this pblm.
\end{minipage}
\end{document}

在此处输入图片描述

相关内容