2

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:

enter image description here

Wulfram
  • 547

2 Answers2

6

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}

My previous answer:

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}

enter image description here

  • 1
    You could/should create an environment which gets surrounded by your hooks. – Skillmon 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"? – Phelype Oleinik Jan 15 '18 at 15:16
  • @Werner Could you explain why, please? – Phelype Oleinik 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. – Wulfram Jan 15 '18 at 16:16
  • As for environments: Yes in fact I am writing a script for myself and wanted to make a proof and an example environment with these rules like in the shown book page. – Wulfram Jan 15 '18 at 16:18
  • @PhelypeOleinik because syntactically this cries for being an environment as it is one block of content surrounded by something formatting it. – Skillmon Jan 15 '18 at 16:32
  • @Wulfram It doesn't necessarily has to be done with TikZ, but its far more straightforward than playing with rules. To create something like that you can rename the hooked environment, create an example counter and add \textbf{EXAMPLE \theexample} after the hook. – Phelype Oleinik Jan 15 '18 at 16:48
  • @Skillmon Saying it like this makes sense :). I just thought it was something more... Thanks for the suggestion though. – Phelype Oleinik Jan 15 '18 at 16:49
  • @PhelypeOleinik: Firstly, you require a \par in order for the block components to be set on their own line. \lipsum issues that by default so it doesn't show in your code. Secondly, here is an example that highlights what happens around a bad page break. – Werner Jan 15 '18 at 16:49
  • @Werner Thanks! I completely forgot that a \par could be necessary there. As for the page break, do you have any suggestion on how to fix that? Feel free to edit my post if you wish :) – Phelype Oleinik Jan 15 '18 at 17:14
6

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} 

enter image description here

Bernard
  • 271,350