How to write underscore (a_b) in LaTeX?
In this tutorial, you will learn how to print underscore in a LaTeX document with different methods. You can’t print this by using _
directly in your source code, because this symbol is used for superscript.
Underscore in LaTeX text mode
To get an underscore in LaTeX text mode, you can use the default command \textunderscore
or {\_}
. You can also use \_
but I recommend using this {\_}
.
\documentclass{article} \begin{document} One\_two\_three Underscore{\_}in{\_}text Code\textunderscore Speedy \end{document}
Output:
Underscore in LaTeX math mode
For math mode, you use the text mode commands {\_}
or \textunderscore
to print the underscore (Using {\_}
is recommended in math mode). You can also use the \verb||
command to print anything without compiling that.
\documentclass{article} \begin{document} $$ One\_two\_three $$ $$ Underscore{\_}in{\_}mathmode $$ $$ Code\textunderscore Speedy $$ $$ \verb|A_B| $$ \end{document}
Output:
Long or a custom size underscore in LaTeX
If you want an underscore with a custom size, you can use the \underline{\hspace{<length>}}
command.
\documentclass{article} \begin{document} Name\underline{\hspace{3cm}} \hfill Date\underline{\hspace{3cm}} \end{document}
Output:
Leave a Reply