How to insert tab space in LaTeX?

You are all familiar with the term “tab space”. Because words are separated by spaces with this tab button on any electronic or digital keyboard.

Simply put, tab space returns us some amount of horizontal space.

LaTeX has many commands to represent this horizontal space. Many of you will think that LaTeX has a default \tab command to complete this task, but there is no default command.

And, there is a \tab command inside tabto package.

Pre-define command for horizontal space

There are many commands in LaTeX to represent horizontal space, some of the popular commands are selected below. You can try the rest if you want.

\hspace{length}
\quad
\qquad
\documentclass[12pt]{article}
\usepackage[margin=1.5cm]{geometry,xcolor}
\begin{document}
\pagecolor{yellow!20!white}
\section*{Use hspace command }

Lorem ipsum \verb|\hspace{1cm}| \rule{1cm}{1pt} dolor sit amet, consectetur \verb|\hspace{2cm}| \rule{2cm}{1pt} adipiscing elit, sed \verb|\hspace{3cm}| \rule{3cm}{1pt} do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat \verb|\hspace{5cm}| \rule{5cm}{1pt}.

\vspace{1cm}

Aenean eros \hspace{10px} tortor, iaculis id neque eget, vulputate sollicitudin nisl. Nunc interdum \hspace{20px} leo nisl, sit amet ultricies orci aliquam convallis. Donec lobortis elementum elit, at imperdiet \hspace{18px} dui dictum et.

\section*{Use quad and qquad commands}

Suspendisse porta \verb|\quad| \rule{1em}{1pt} mi non nisl ornare, \verb|\qquad| \rule{2em}{1pt} non egestas ligula hendrerit. Fusce feugiat sapien nec nisi venenatis \verb|\quad\quad| \rule{2em}{1pt} ullamcorper. Vestibulum ut facilisis mi, lacinia rutrum \verb|\qquad\qquad| \rule{4em}{1pt} velit. 

\vspace{1cm}

 Phasellus dolor est, \quad blandit eu orci id, ultricies luctus dolor. Suspendisse et nisi a \qquad quam posuere ultricies. Ut eleifend vestibulum magna vel lobortis. Proin in sapien condimentum, condimentum neque id, \quad \quad cursus magna. Nam id consectetur diam, et pellentesque lectus. Morbi lobortis, nisi sit amet suscipit luctus, lectus nibh gravida lorem, \qquad \quad dictum pulvinar urna diam ultrices dolor. 
 
\end{document}

Output :

Create own command for tab space

Whenever it comes up to create a new command in LaTeX. Then we will take help of \newcommand. But, although the syntax of this command is complicated, it can do a lot of functional work.

Note the syntax below. Usage of this command has been simplified.

\newcommand[cmd][exp] % Without argument
\newcommand[cmd][number_of_arg][exp] % With argument
\newcommand[cmd][number_of_arg][opt_arg][exp] 
# for example
\newcommand\tab[1][.5cm]{\hspace*{#1}}
\newcommand\tabx{\quad}
\documentclass[12pt]{article}
\usepackage[margin=1.5cm]{geometry,xcolor}
\newcommand\tab[1][.5cm]{\hspace*{#1}}
\begin{document}
\pagecolor{red!10!white}
\section*{Use length unit cm}
Aenean eu accumsan \tab lorem. Integer sit amet luctus \tab[1cm] dui, sit amet ultrices tellus. Duis vel ipsum ut dui fringilla ullamcorper auctor a magna. \tab{1.5cm} Fusce commodo odio vehicula, pharetra risus vel, ultricies dolor. 

\vspace{1cm}

.5cm \tab 1.5cm \tab[1.5cm] 2cm \tab[2cm] end

.5cm \rule{.5cm}{1pt}1.5cm \rule{1.5cm}{1pt} 2cm \rule{2cm}{1pt} end

\vspace{1cm}

\section*{Use length unit em}

Vestibulum sed \tab[20px] mattis mauris, nec volutpat \tab[1in] diam. Donec fermentum, diam sagittis posuere iaculis, velit diam elementum enim, \tab[1.5em]  eu varius erat turpis non urna.

\vspace{1cm}

1em \tab[1em] 2em \tab[2em] 3em \tab[3em] end

1em \rule{1em}{1pt} 2em \rule{2em}{1pt} 3em \rule{3em}{1pt} end

\vspace{1cm}

\section*{Use length unit inch}

Curabitur posuere nibh a magna \tab[.5in] tristique faucibus. Aliquam \tab[1in]elementum massa sit amet posuere consequat.\tab[1.5in] Sed dignissim ipsum ut hendrerit lobortis. Ut sed nulla ac lectus vulputate laoreet in vel felis. Proin sodales mi sed consequat ultricies. Suspendisse \tab[1.6in] elit congue egestas vitae sed velit. Aenean mollis nibh enim, eu iaculis sem vehicula ut. 
\end{document}

Output :

Tabbing environment

Syntax of this environment looks complicated. But, its usage will impress you. Let’s understand the following syntax.

\begin{tabbing}
  Text at stop 1 \= Text at stop 2 \= Text at stop 3 \\
   Second line \> Second line \> Second line \\
   Third line \> Third line \> Third line \\
\end{tabbing}

\= : defines stop positions as universal, where each line below is treated as a tab stop position.

\> : moves from one stop to another. You can directly jump from the first stop to the third stop by this \>.

\\ : It creates a new line.

Four examples are provided in the following code, along with four types of concepts explained.

\documentclass[12pt]{article}
\usepackage[margin=1.5cm]{geometry,xcolor}
\begin{document}
\pagecolor{purple!15!white}
\section*{Single tab stop}

\begin{tabbing}
  Text at stop 1 \=  Text at stop 2 \\
   Second line \> Second line  \\
   Third line \> Third line  \\
\end{tabbing}

\section*{Multiple stop}

\begin{tabbing}
  Text at stop 1 \=  Text at stop 2 \= Text at stop 3 \\
   Second line \> Second line \> Second line \\
   Third line \> Third line \> Third line \\
\end{tabbing}

\section*{Custom stop positions}

\begin{tabbing}
First Column \= Second Column \= \\
Column 1 \> Column 2  \\
\> Column2 \> Column 3 \\
\> \> Column 3 \\
Column 1 \> \> Column 3
\end{tabbing}

\section*{Add horizontal and vertical space}

\begin{tabbing}
\textbf{First Stop } \qquad \= \textbf{Second Stop} \\[6pt]
Column 1 \> Column 2 \\
\> Column 2 \hspace{2cm} \= \textbf{Third Stop}\\[6pt]
\> \> Column 3 \\
Column 1 \> Column 2 \> Column 3 \\

\end{tabbing}

\end{document}

Output :

“You remember when you used to press Tab to organize the data into a table”. Yes, tabbing  environment allows data to be organized in a table format. Check out these examples below

\documentclass[12pt]{article}
\usepackage[margin=1.5cm]{geometry,xcolor,lipsum}
\begin{document}
\pagecolor{yellow!20!white}

\section*{Table of countries, capitals, and languages}
\lipsum[1][1-6]
\begin{tabbing}
\textbf{Country} \qquad \= \textbf{Capital} \qquad \= \textbf{Language} \\[6pt]
US \> W, D.C. \> English \\
France \> Paris \> French \\
Germany \> Berlin \> German \\
Japan \> Tokyo \> Japanese \\
India \> Delhi \> Hindi \\
\end{tabbing}

\begin{tabbing}
\textbf{Country} \qquad \= \textbf{Capital} \\[6pt]
US \> W, D.C. \\
\> \hspace{2.5cm} \= \textbf{Language} \\[6pt]
Germany \> Berlin \> German \\
Japan \> Tokyo \> Japanese \\
India \> Delhi \> Hindi \\
\end{tabbing}

\section*{Table of mathematical symbols}

\lipsum[2][1-5]

\begin{tabbing}
\textbf{Symbol} \qquad \= \textbf{Meaning} \\
$\alpha$ \> Alpha \\
$\beta$ \> Beta \\
$\gamma$ \> Gamma \\
$\delta$ \> Delta \\
$\omega$ \> Omega \\
\end{tabbing}

\section*{Table of schedule of events}

\begin{tabbing}
\textbf{Time} \hspace{1.5cm} \= \textbf{Event} \\[6pt]
9:00 am \> Registration \\
10:00 am \> Opening Keynote \\
11:30 am \> Breakout Sessions \\
1:00 am \> Lunch \\
2:30 am \> Panel Discussion \\
4:00 am \> Closing Remarks \\
\end{tabbing}

\lipsum[4][1-8]

\begin{tabbing}
\textbf{Header 1} \hspace{2cm} \= \textbf{Header 2} \hspace{2cm} \= \textbf{Header 3} \hspace{2cm} \= \textbf{Header 4} \\[5pt]
Row 1, Col 1 \> Row 1, Col 2 \> Row 1, Col 3 \> Row 1, Col 4 \\
Row 2, Col 1 \> Row 2, Col 2 \> Row 2, Col 3 \> Row 2, Col 4 \\
Row 3, Col 1 \> Row 3, Col 2 \> Row 3, Col 3 \> Row 3, Col 4 \\
Row 4, Col 1 \> Row 4, Col 2 \> Row 4, Col 3 \> Row 4, Col 4 \\
\end{tabbing}
\lipsum[5][1-8]
\end{document}

Output :

Use tabto command

Using the tabto package is not a best practice. Because you cannot use \tab or \tabto command in all cases. But, if you want to indent the beginning of a text, paragraph, and other text element, you can.

Conclusion(Best Practice)

I hope you understand each code with syntax. If you are using paragraphs or between text, use predefined spaces like \quad, \qquad and \hsapce{arg}. A tabbing environment is the best practice to arrange data in an organized way using tab space.

Md Jidan Mondal

LaTeX expert with over 10 years of experience in document preparation and typesetting. Specializes in creating professional documents, reports, and presentations using LaTeX.

Leave a Comment

Your email address will not be published. Required fields are marked *