How do you make(draw) a horizontal line in LaTeX?

LaTeX provides us with several commands to draw horizontal lines in the document. In some cases, we need some arguments and in some cases we don’t. So in this tutorial, we will discuss all methods of drawing horizontal lines in LaTeX.

Use \rule command with arguments for horizontal line

The easiest way to draw horizontal lines in Latex is to use the \rule[raise-height]{length}{thickness} command. And here you can pass length and thickness in arguments as you need.

You can also use an optional argument to move the line from the neutral location (above or below). To increase the vertical position, use a positive value and to decrease it, use a negative value.

If you want to draw a horizontal line under a paragraph, the same length as the paragraph, a better option is to use the \textwidth command as the length. You can also use the \noindent command to give the line a better look. Below is the syntax

\par\noindent\rule{\textwidth}{0.5pt}

\documentclass{article}
\usepackage{lipsum}
\begin{document}
 \begin{center}
   \verb|Without using \noindent|
 \end{center}
 \lipsum[1][1-3]
 \par\rule{\textwidth}{0.5pt} 
 \par
 \lipsum[1][1-3]
 \begin{center}
   \verb|Using \noindent|
 \end{center}
 \lipsum[1][1-3]
 \par\noindent\rule{\textwidth}{0.5pt}
 \par
 \lipsum[1][1-3]
\end{document}

Output :

Line indent can be controlled by \rule command.

\hrule command without argument

LaTeX provides another command for drawing horizontal lines which is \hrule. This command does not require any arguments. It is usually used between two paragraphs, so if you want some space above and below the line, you can use the \vspace{} command.

\documentclass{article}
\usepackage{lipsum}
\begin{document}
 \lipsum[1][1-3]
  \vspace{4pt}
    \hrule
  \vspace{4pt}
 \lipsum[1][1-3]
\end{document}

Output :

\hrule commands will not have any arguments. That is, you cannot customize the line.

Horizontal line size is resized by \line command

Of the previous methods, the \line command is more versatile. This command allows you to set the slope for the line you want to draw. So you can draw different lines and horizontal lines too. The syntax is

\line(x-slope,y-slope){length}

For horizontal line, you need to use (1,0) as first argument and can pass length as you need. Also, to center the position of the line, you can use center Environment.

\documentclass{article}
\usepackage{lipsum}
\begin{document}
 \lipsum[1][1-3]
 \begin{center}
    \line(1,0){340}
 \end{center}
 \lipsum[1][1-3]
 \begin{center}
   \line(1,0){70}
 \end{center}
\end{document}

Output :

You can change the size of the line according to your needs.

Use \hline command in LaTeX

LaTeX provides the \hline command to draw horizontal lines in a simple way. This command takes no arguments. This means you cannot customize the line. For vertical space, you can use \vspace command.

You can draw double lines by using two \hline commands in a row with a small gap between the lines.

\documentclass{article}
\usepackage{lipsum}
\begin{document}
 \lipsum[1][1-3] 
 \vspace{5pt}
   \hline
 \vspace{5pt}
 \lipsum[1][1-3] 
 \vspace{5pt}
 \hline
 \hline
\end{document}

Output :

Use \hline command in latex.

Line and text are inserted on same line by \hrulefil command

The functionality of the \hrulefill command is slightly different from the above methods. Its functionality is that if there is extra space at the end of the last line, then the horizontal line starts by sharing the space.

You can also draw lines from the next line if you want with the \par command. The \hrulefill command is used by many for titles or their unique purpose. And don’t forget to use \noindent to give the line a better look. Some examples are given below for better understanding.

\documentclass{article}
\usepackage{lipsum}
\begin{document}
  \begin{center}
    \verb|\hrulefill use for Title|
 \end{center}
 \noindent\hrulefill Title \noindent\hrulefill
 \begin{center}
    \verb|Without using \par|
 \end{center}
 \lipsum[1][1-2]
 \noindent\hrulefill
 \begin{center}
    \verb|Using \par|
 \end{center}
 \lipsum[1][1-2]
 \par\noindent\hrulefill
\end{document}

Output :

Use \hrulefill command in latex.

Draw horizontal dot line in LaTeX

LaTeX provides a command called \dotfill to draw horizontal dot lines. The functionality of this command is same as \hrulefill only in this case the dotted line is drawn. It is generally used to give a better look to the document.

\documentclass{article}
\usepackage{lipsum}
\begin{document}
 \begin{center}
    \verb|\dotfill use for Title|
 \end{center}
 \noindent\dotfill Title \noindent\dotfill
 \begin{center}
    \verb|Without using \par|
 \end{center}
 \lipsum[1][1-2]
 \noindent\dotfill
 \begin{center}
    \verb|Using \par|
 \end{center}
 \lipsum[1][1-2]
 \par\noindent\dotfill
\end{document}

Output :

Draw horizontal dot line by \dotfill.

One request!

Don't forget to share if I have added any value to your education life. See you again in another tutorial. thank you!

Facebook iconTwitter iconWhatsapp iconPinterest icon

Leave a Comment

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