# How to make "rule with hooks"

I guess this is a very basic question but I didn't find anything. Also didn't know what to search for, sry for the stupid title.

How can I make a "rule with hooks", be it horizontal or vertical, with a certain lenght and thickness, such as

\rule{\linewidth}{1pt}


But like in the picture below:

• – Werner
Jan 12 '18 at 21:15

## Update:

As requested, an environment for "hooked" text. The syntax is:

\begin{hooked}[<optional line configuration (TikZ syntax)>]%
{<Hook length (below horizontal rule)>}%
{<The amount the hook advances to the margin>}%
{<The space between the hook and the text>}
Text
\end{hooked}


I added a space between the hook and the text. It looks better with a little space.

The code:

\newenvironment{hooked}[4][line width=1pt]{% Default line appearance
\noindent\hspace{-#3}% Drag the hook left by \hookmargin
\begin{tikzpicture}% Draw the opening hook
%                                          V---V Why can't use 2#3 instead of #3+#3?
\draw [#1] (0,-#2) -- (0,0) -- (\linewidth+#3+#3,0) -- (\linewidth+#3+#3,-#2);
\end{tikzpicture}%
\par% We need a \par to avoid text in the same line as the rules (thanks @Werner!)
\vspace{#4}% Add a space between the hook and the text
\def\closehook{% Defining a closing hook (for some reason, putting this in the \end{hooked} definition doesn't work)
\par% And another \par here!
\vspace{#4}% Add the same sspace as before
\noindent\hspace{-#3}% Doing the same...
\begin{tikzpicture}
\draw [#1] (0, #2) -- (0,0) -- (\linewidth+#3+#3,0) -- (\linewidth+#3+#3, #2);
\end{tikzpicture}%
}%
}{%
\closehook% Inserting the closing hook
}


MWE:

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}

\newenvironment{hooked}[4][line width=1pt]{%
\noindent\hspace{-#3}%
\begin{tikzpicture}
\draw [#1] (0,-#2) -- (0,0) -- (\linewidth+#3+#3,0) -- (\linewidth+#3+#3,-#2);
\end{tikzpicture}\par\vspace{#4}%
\def\closehook{%
\par\vspace{#4}\noindent\hspace{-#3}%
\begin{tikzpicture}
\draw [#1] (0, #2) -- (0,0) -- (\linewidth+#3+#3,0) -- (\linewidth+#3+#3, #2);
\end{tikzpicture}%
}}{\closehook}

\begin{document}

\begin{hooked}[line width=1pt, blue, dash dot]{2em}{2em}{-1em}

\lipsum[1-5]

\end{hooked}

\end{document}


Using TikZ:

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}

\newlength{\hooklength}
\setlength{\hooklength}{1em}% The length of the hook below the horizontal rule

\newlength{\hookmargin}
\setlength{\hookmargin}{2em}% The amount the hook enters the margin to each side

\newlength{\hookwidth}
\setlength{\hookwidth}{1pt}% The thickness of the rules

\newcommand{\hookdown}{%
\noindent\hspace{-\hookmargin}%
\begin{tikzpicture}
\draw [line width = \hookwidth] (0,-\hooklength) -- (0,0) -- (\textwidth+2\hookmargin,0) -- (\textwidth+2\hookmargin,-\hooklength);
\end{tikzpicture}%
}

\newcommand{\hookup}{%
\noindent\hspace{-\hookmargin}%
\begin{tikzpicture}
\draw [line width = \hookwidth] (0,\hooklength) -- (0,0) -- (\textwidth+2\hookmargin,0) -- (\textwidth+2\hookmargin,\hooklength);
\end{tikzpicture}%
}

\begin{document}
\hookdown

\lipsum[1]

\hookup
\end{document}


• You could/should create an environment which gets surrounded by your hooks. Jan 12 '18 at 20:41
• This would probably not work correctly around the page boundary.
– Werner
Jan 12 '18 at 21:25
• @Skillmon Done! (Sorry for the delay :)). If I may ask, why "should"? Jan 15 '18 at 15:16
• @Werner Could you explain why, please? Jan 15 '18 at 15:16
• Thanks for the answer. I have never used any drawing packages and thought this is so basic it doesn't need one. Jan 15 '18 at 16:16

A simple solution with quoting and mathtools:

\documentclass{article}
\usepackage{mathtools}
\usepackage{quoting}
\usepackage{lipsum}

\begin{document}

\lipsum[1]
\begin{quoting}[leftmargin = 0.75em, rightmargin = 0.75em, indentfirst = false,%
begintext = \noindent{\centering\hspace{-0.75em}$\overbracket[1pt][1ex]{\hspace*{\textwidth}}$}\vspace{-1.1ex}\par\nopagebreak\noindent, %
endtext = \vspace{-2.25ex}\nopagebreak\noindent\centering{\hspace{-0.75em}$\underbracket[1pt][1ex]{\hspace*{\textwidth}}$}]
\lipsum[1]
\end{quoting}
\lipsum[2]

\end{document}