Escaping _ efficiently in Tabular environment, LaTeX

How can you escape underscores only in the tabular environment without the use of \_?

This thread discusses about underscore in general. I cannot use the environment verbatim nor the package underscore.

Sample data

\begin{tabular}{| l | l | p{5cm} |} 
\hline 
delete_a_question.php&poistaa kysymyksen&setterit \\ \hline 
edit_question.php&muokkaa kysymyst\"{a}&getterit, HTML koodin generointia \\ \hline 
--cut--
\end{tabular}

Upvotes: 1

Views: 2755

Answers (2)

Will Robertson
Will Robertson

Reputation: 64580

Rather than hacking with catcodes manually, the underscore package does it for you so that _ works in text as a printed underscore, while still behaving as a subscript modifier in maths mode. Just load the package.

Upvotes: 7

dreamlax
dreamlax

Reputation: 95335

\bgroup
  \catcode`\_=13%
  \def_{\textunderscore}%
  \begin{tabular}{|l|l|p{4.5cm}}
    test_444 & 555 & 4_4\\\hline
  \end{tabular}
\egroup

And now for some normal maths: $a_i=3$.

Here, I change the category code of the underscore character so that it is active (this means that I can give the underscore a macro definition). I define the underscore character to output an actual underscore character.

The \bgroup and \egroup limit the effects of redefining the underscore character.

Upvotes: 5

Related Questions