7

I want to emulate a feature from a few word processing programs (e.g. Microsoft Word, LibreOffice Writer) where I could (somewhat) arbitrarily insert a bottom border below any text/paragraph. How can I do this in LaTeX?

Edit: Just to clarify, what I want is pretty much a horizontal line across the page just below the text. Like this:

Bottom border

lockstep
  • 250,273
kibibyte
  • 417
  • 2
  • 5
  • 8

3 Answers3

15

With a slight modification from @egreg's answer to Shift horizontal line to the left, the following minimal working example (MWE) provides \myrule[<thickness>][<gap>][<color>], that places a rule of thickness <thickness> between paragraphs (default is 1pt). Additionally, the second optional argument allows you to increase the gap between the line and the preceding/succeeding paragraph (default is 3pt). Finally, the last optional argument allows you to change the colour of the line to <color> (default is black). Colour is provided by means of \color from the xcolor package.

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{xparse}% http://ctan.org/pkg/xparse
\NewDocumentCommand{\myrule}{O{1pt} O{3pt} O{black}}{%
  \par\nobreak % don't break a page here
  \kern\the\prevdepth % don't take into account the depth of the preceding line
  \kern#2 % space before the rule
  {\color{#3}\hrule height #1 width\hsize} % the rule
  \kern#2 % space after the rule
  \nointerlineskip % no additional space after the rule
}
\begin{document}
\lipsum[1]

\myrule

\lipsum[2]

\myrule[10pt][5pt]

\lipsum[3]

\myrule[5pt][5pt][orange]

\lipsum[4]

\end{document}

enter image description here

Werner
  • 603,163
13

There are probably many ways to do this. Have you tried issuing the command

\hrule

on a line by itself?

Mico
  • 506,678
4

Here's another approach using an environment. The advantage of this approach is that you can decorate the content of the environment globally in your preamble. You could combine this idea with Werner's to make the border more colourful.

I have used the needspace package to make sure that the \hrule doesn't get separated from the last line of the paragraph.

\documentclass{article}

\usepackage{lipsum}     % needed for sample text
\usepackage{needspace}  % provides the \needspace command
\newenvironment{bottomborder}%
{}  % code to be processed before the environment begins
{\needspace{\baselineskip}\hrule} % code to be processed after the environment ends
\begin{document}

\begin{bottomborder}
\lipsum[1-3] 
\end{bottomborder}

\end{document}
cmhughes
  • 100,947