1

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}
Joshua
  • 40,822
  • 8
  • 72
  • 132
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

2 Answers2

7

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.

Will Robertson
  • 62,540
  • 32
  • 99
  • 117
5
\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.

dreamlax
  • 93,976
  • 29
  • 161
  • 209