[Tex/LaTex] How to handle % character in LaTeX

charactersverbatim

I am working on special character handling and my text is having % as one the special character which is treated as comment and anything after that is not printed. I m using verb as suggested in my previous thread but still pblm.

How to handle special characters in LaTeX?

Below is my code.

\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}

Best Answer

To typeset verbatim material you need to use, for example, the verbatim environment (in your code snippet you only selected a font for verbatim material) and manually introduce line breaks (I commented out some lines because I don't have 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}

enter image description here

The fancyvrb packages offers more possibilities and enhanced verbatim environments/commands; the listings package extends even more the possibilities.

If all that you need is to typeset the percentage character, use \%:

\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}

enter image description here

Related Question