\separate
我希望我的部分文本被“框起来”。到目前为止,我已经通过以下 MWE 中的命令生成了水平线:
\documentclass{article}
\newcommand\separate{\medskip\hrule\medskip} % nice page-long underscores
\begin{document}
Here is introductory text.
\separate
Here is text in the frame.
\separate
Here is concluding text.
\end{document}
两个问题:
1) 如何使水平线稍微延伸到外边缘?(以便它仅超出其框架的文本0.2英寸左右......)
2) 如何添加代码来生成水平线和垂直线?我希望“框架”最终看起来像这样:
----------------------------
|
|
----------------------------
编辑:
更具体地说,我希望它能与环境一起工作fullwidth
,如以下(更新的)MWE:
\documentclass{article}
\usepackage{fullwidth}
\newcommand\separate{\medskip\hrule\medskip} % nice page-long underscores
\begin{document}
Here is introductory text.
\begin{fullwidth}[outermargin = -4cm, width = \linewidth + 4cm]
\separate
Here is text in the frame
\separate
\end{fullwidth}
Here is concluding text.
\end{document}
答案1
非 TikZ 解决方案
\documentclass{article}
\usepackage{xcolor,graphicx,lipsum}
\parindent0pt
\begin{document}
\def\boxit #1{%
\parindent0pt
\leavevmode
\hbox{\vbox{%
\hrule
%
\vbox to 0pt{\vrule height50pt width1pt}
\leftskip10pt\rightskip10pt
\vskip10pt%
#1%
\vskip-50pt\vbox to 0pt{\hskip\dimexpr\hsize-10pt\relax\vrule height50pt width1pt}
\vskip50pt
\hrule
}%
}}
\boxit{\lipsum[2]}
\end{document}
编辑
要使用全宽包,需要进行一些小的调整;带有键值接口的完整代码有点长,所以我将其粘贴在https://gist.github.com/1971055。
答案2
我很确定 TikZ 会在这里有所作为,因为它在这些方面更加熟练和具有装饰性。但是,可以使用规则组合来获得此布局。我决定使用环境而不是两个单独的宏,因为它似乎更合适 - 环境允许开始和结束声明。
\documentclass{article}
\usepackage{showframe}% http://ctan.org/pkg/showframe
\newenvironment{separateA}
{\par\nobreak%
\noindent\smash{\makebox[\textwidth]{%
\rule[-.25\baselineskip]{.4pt}{\dimexpr.25\baselineskip+.4pt}% left hang
\rule{\dimexpr\textwidth+.4in-.8pt}{.4pt}% horizontal rule
\rule[-.25\baselineskip]{.4pt}{\dimexpr.25\baselineskip+.4pt}% right hang
}}}
{\par\nobreak%
\noindent\smash{\makebox[\textwidth]{%
\rule[.5\baselineskip]{.4pt}{.25\baselineskip}% left hung
\rule[.5\baselineskip]{\dimexpr\textwidth+.4in-.8pt}{.4pt}% horizontal rule
\rule[.5\baselineskip]{.4pt}{.25\baselineskip}% right hung
}}}
\newenvironment{separateB}
{\par\nobreak%
\noindent\smash{\makebox[\textwidth]{%
\rule[-.25\baselineskip]{.4pt}{\dimexpr.25\baselineskip+.4pt}% left hang
\rule{\dimexpr\textwidth+.4in-.4pt}{.4pt}% horizontal rule
%\rule[-.25\baselineskip]{.4pt}{\dimexpr.25\baselineskip+.4pt}% right hang
}}}
{\par\nobreak%
\noindent\smash{\makebox[\textwidth]{%
%\rule[.5\baselineskip]{.4pt}{.25\baselineskip}% left hung
\rule[.5\baselineskip]{\dimexpr\textwidth+.4in-.4pt}{.4pt}% horizontal rule
\rule[.5\baselineskip]{.4pt}{.25\baselineskip}% right hung
}}}
\newenvironment{separateC}
{\par\nobreak%
\noindent\smash{\makebox[\textwidth]{%
%\rule[-.25\baselineskip]{.4pt}{\dimexpr.25\baselineskip+.4pt}% left hang
\rule{\dimexpr\textwidth+.4in-.4pt}{.4pt}% horizontal rule
\rule[-.25\baselineskip]{.4pt}{\dimexpr.25\baselineskip+.4pt}% right hang
}}}
{\par\nobreak%
\noindent\smash{\makebox[\textwidth]{%
\rule[.5\baselineskip]{.4pt}{.25\baselineskip}% left hung
\rule[.5\baselineskip]{\dimexpr\textwidth+.4in-.4pt}{.4pt}% horizontal rule
%\rule[.5\baselineskip]{.4pt}{.25\baselineskip}% right hung
}}}
\begin{document}
Some fully boxed text, using \verb|separateA|:
\begin{separateA}
Here is text in the frame.
\end{separateA}
Some partially boxed text (left and right), using \verb|separateB|:
\begin{separateB}
Here is text in the frame.
\end{separateB}
Some partially boxed text (right and left), using \verb|separateC|:
\begin{separateC}
Here is text in the frame.
\end{separateC}
Here is concluding text.
\end{document}
为了区别起见,上述 MWE 提供了三种环境(尽管它们实际上完全相同):separateA
打印“完全装箱”的块,同时separateB
打印“部分装箱”的块(左右)以及separateC
“部分装箱”的块(从右到左)。注意使水平分隔正好\textblock+.4in
宽,恰好悬在.2in
两边的边缘上。
构建一个单一环境(比如说)来执行此操作会很容易separate
,并使用可选参数来控制挂起/挂起的位置。
showframe
用于突出显示文本块边界,并指示和强调文本边缘外的悬垂部分。
答案3
\documentclass{article}
\newcommand\separate[1][]{%
\par\noindent
\ifx\relax#1\relax
\makebox(0,0){\rule[-2\normalbaselineskip]{\fboxrule}{\normalbaselineskip}}%
\kern-0.5\fboxrule\rule{1.1\textwidth}{\fboxrule}%
\else
\rule{1.1\textwidth}{\fboxrule}%
\makebox(0,0){\rule[\normalbaselineskip]{\fboxrule}{\normalbaselineskip}}%
\fi\par}
\begin{document}
Here is introductory text.
\separate
Here is text in the frame.
\separate[up]
Here is concluding text.
\end{document}
答案4
这是 Metapost 的解决方案(在 ConTeXt 中)。我定义了一个MP背景在 metapost 中,可以将其插入任何接受参数的 ConTeXt 对象background
。
\startuniqueMPgraphic {splitframe}
newpath topborder, bottomborder;
newpath BackgroundBox;
BackgroundBox := OverlayBox enlarged (0.2cm);
bottomborder = point 0 of BackgroundBox -- point 1 of BackgroundBox
-- point 1.2 of BackgroundBox ;
topborder = point 2 of BackgroundBox -- point 3 of BackgroundBox
-- point 3.2 of BackgroundBox ;
draw bottomborder withpen pencircle scaled OverlayLineWidth
withcolor OverlayLineColor ;
draw topborder withpen pencircle scaled OverlayLineWidth
withcolor OverlayLineColor ;
setbounds currentpicture to OverlayBox ;
\stopuniqueMPgraphic
\defineoverlay [splitframe] [\uniqueMPgraphic{splitframe}]
举例来说,考虑为侧边浮动和文本背景添加框架。
\definebackground
[splitframe]
[background=splitframe,
rulethickness=1.5pt,
framecolor=blue,
width=broad,
frame=off]
\starttext
\placefigure[right,none]{}
{\externalfigure[cow][background=splitframe,width=0.3\textwidth,framecolor=red]}
\startsplitframe
\input tufte
\stopsplitframe
\stoptext