答案1
更新:
根据要求,为“挂钩”文本提供一个环境。语法如下:
\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}
我在钩子和文本之间添加了一个空格。留一点空间看起来会更好。
代码:
\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
}
梅威瑟:
\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}
我之前的回答:
使用 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}
答案2
一个简单的解决方案是使用 quoting
和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}