简体   繁体   中英

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}

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM