# add horizontal rule to latex with code examples

In LaTeX, a horizontal rule (also known as a "horizontal line") can be added to a document using the \hrule command. This command creates a line that spans the entire width of the current text block.

Here is an example of how to add a horizontal rule to a LaTeX document:

\documentclass{article}
\begin{document}

This is some text that appears above the horizontal rule.

\hrule

This is some text that appears below the horizontal rule.

\end{document}


You can also customize the appearance of the horizontal rule by specifying certain options. For example, you can change the thickness of the line using the \thickness option. Here is an example of how to create a horizontal rule that is 2pt thick:

\documentclass{article}
\begin{document}

This is some text that appears above the horizontal rule.

\hrule \thickness{2pt}

This is some text that appears below the horizontal rule.

\end{document}


You can also change the width of the horizontal rule using the \width option. Here is an example of how to create a horizontal rule that is 80% of the width of the current text block:

\documentclass{article}
\begin{document}

This is some text that appears above the horizontal rule.

\hrule \width{0.8\textwidth}

This is some text that appears below the horizontal rule.

\end{document}


You can also change the alignment of the horizontal rule using the \align option. Here is an example of how to create a horizontal rule that is centered within the current text block:

\documentclass{article}
\begin{document}

This is some text that appears above the horizontal rule.

\hrule \align{center}

This is some text that appears below the horizontal rule.

\end{document}


You can also change the color of the horizontal rule using the \color option. Here is an example of how to create a horizontal rule that is red:

\documentclass{article}
\usepackage{xcolor}
\begin{document}

This is some text that appears above the horizontal rule.

\hrule \color{red}

This is some text that appears below the horizontal rule.

\end{document}


In summary, the \hrule command is a simple and flexible way to add horizontal rules to a LaTeX document. By specifying different options, you can customize the appearance of the horizontal rule to suit your needs.

In addition to the \hrule command, there are several other ways to create horizontal lines in LaTeX. One common method is to use the \rule command, which allows you to specify the width, height, and depth of the line. Here is an example of how to create a horizontal line that is 10pt wide and 1pt thick:

\rule{\linewidth}{1pt}


Another way to create a horizontal line is to use the \line command, which allows you to specify the starting and ending coordinates of the line. Here is an example of how to create a horizontal line that spans the entire width of the page:

\line(1,0){\paperwidth}


You can also use the \rule or \line command to create horizontal lines with different styles, such as double or dotted lines.

To create a double horizontal line, use the \doubleRule command from the booktabs package.

\usepackage{booktabs}
\doubleRule


To create a dotted horizontal line, you can use the \hdashline command from the makecell package.

\usepackage{makecell}
\hdashline


Another way to create a horizontal line with a specific style is to use the \rule[raise]{width}{thickness} command, where 'raise' is the distance from the baseline to the center of the rule and 'width' and 'thickness' are the width and height of the rule. Here is an example of how to create a horizontal line that is 2pt thick with a 1pt gap above and below it:

\rule[1pt]{\linewidth}{2pt}


Finally, you can also create horizontal lines using the \rule command with a specific dash pattern, this can be achieved using the \dashbox command from the dashbox package, the first argument is the width of the line, the second is the height, the third is the thickness and the last one is the dashed pattern. Here is an example of how to create a horizontal line that is 10pt wide, 1pt thick and dashed:

\usepackage{dashbox}
\dashbox{10pt}{1pt}{1pt}{2,3}


In summary, there are many ways to create horizontal lines in LaTeX, and each method has its own advantages and disadvantages. The \hrule command is a simple and easy-to-use method for creating horizontal lines, but it may not always provide the level of customization that you need. Other methods, such as the \rule, \line, \doubleRule, \hdashline and \dashbox commands, can also be used to create horizontal lines with different styles, widths, and thicknesses, and they can be useful in specific situations where more customization is needed.

## Popular questions

Q: How can I add a horizontal rule to a LaTeX document?
A: You can add a horizontal rule to a LaTeX document using the \hrule command.

Q: How can I change the thickness of a horizontal rule in LaTeX?
A: You can change the thickness of a horizontal rule in LaTeX by using the \thickness option in conjunction with the \hrule command. For example, \hrule \thickness{2pt} will create a horizontal rule that is 2pt thick.

Q: How can I change the width of a horizontal rule in LaTeX?
A: You can change the width of a horizontal rule in LaTeX by using the \width option in conjunction with the \hrule command. For example, \hrule \width{0.8\textwidth} will create a horizontal rule that is 80% of the width of the current text block.

Q: How can I change the alignment of a horizontal rule in LaTeX?
A: You can change the alignment of a horizontal rule in LaTeX by using the \align option in conjunction with the \hrule command. For example, \hrule \align{center} will create a horizontal rule that is centered within the current text block.

Q: How can I change the color of a horizontal rule in LaTeX?
A: You can change the color of a horizontal rule in LaTeX by using the \color option in conjunction with the \hrule command. For example, \hrule \color{red} will create a red horizontal rule. You will also need to use the xcolor package for this \usepackage{xcolor}

### Tag

Typesetting

Posts created 2498

## date format in django template with code examples

Begin typing your search term above and press enter to search. Press ESC to cancel.