How to draw horizontal lines in LaTeX?

In this tutorial, you will learn how to draw different types of horizontal lines in a LaTeX document.

Dwar horizontal line with \rule command

With the default command \rule you can draw a horizontal line and customize the line with these options.

\rule[<h>]{<w>}{<t>}

Here,

  • <h>: Use any length to change the position of the line from the baseline. The default value is 0. (Optional)
  • <w>: Use any length to set the width of the line. (Mandatory)
  • <t>: Use any value to set the thickness of the line. (Mandatory)

Use the \par command before the rule command to make a new paragraph. Use the \noindent command to get no indent on that line.

\documentclass{article}
\begin{document}

This is a \rule{3cm}{0.5pt} horizontal rule.

This is a \rule[2pt]{5cm}{0.5pt} horizontal rule (vertically center).

\vspace{1cm}

With \textbackslash noindent command:

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

\end{document}

Output:

horizontal line.
You can also use the \hline command, but in this case, you can’t customize the line.

\documentclass{article}
\begin{document}

\noindent With \textbackslash rule command:

\noindent\rule{\linewidth}{0.5pt}

\noindent With \textbackslash hrule command:

\hrule

\vspace{10pt}

\noindent Double horizontal line with \textbackslash hrule command:\\[3pt]
\hrule
\vspace{3pt}
\hrule

\end{document}

Output:

horizontal line.

Use \hrulefil to fill rest of the space inside the text

You can use the \hrulefill to fill the rest of the space in a line with text. If there was an extra space at the end of the line, the \hrulefill command can fill the rest of the space with a horizontal line.

\documentclass{article}
\begin{document}

\noindent This is a demo line, this will end with a horizontal line \hrulefill

\noindent Text 1 \hrulefill Text 2 \hrulefill Text 3

\noindent\hrulefill

\end{document}

Output:

horizontal line.

Dotted horizontal line in LaTeX

If you want a dotted horizontal line then you can use the \dotfill command, this command works similarly to \hrulefill command.

\documentclass{article}
\begin{document}

\noindent This is a demo line, this will end with a horizontal line \dotfill

\noindent Text 1 \dotfill Text 2 \dotfill Text 3

\noindent\dotfill

\end{document}

Output:

dotted horizontal line.

Horizontal line is the same as the page width

If you want a draw horizontal line that is the same width as the page width. Then you have to use the \makebox command, and inside this command, you have to use the \rule command. Use \paperwidth of the size of the line.

\documentclass{article}
\begin{document}

Horizontal line:

\noindent \rule{\linewidth}{0.4pt}

Horizontal line same as page width:

\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\end{document}

Output:

horizontal line same as page width.

Leave a Reply

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