Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want some of my text to be "framed". So far, I have horizontal lines generated by the \separate command in the following 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}

Two questions:

1) How do I make the horizontal line extend just a tiny bit longer into the outer margin? (So that it runs just .2 inches or so beyond the text its framing...)

2) How do I add code generate little vertical lines to the horizontal ones? I want the "frame" to end up looking something like the following:

 ----------------------------
|

                            |
----------------------------

EDIT:

To be more specific, I want this to work with the fullwidth environment, as in the following (updated) 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}
share|improve this question
3  
In this case you should work with mdframed. A similar example is given in the documentation. Please have a look at example 7 in the file mdframed-example-default.pdf –  Marco Daniel Mar 3 '12 at 19:06
add comment

4 Answers

up vote 12 down vote accepted

Non-TikZ solution

\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}

enter image description here

Edit

To work with fullwidth package minor adjustments were necessary; the full code with a key-value interface is a bit long so I pasted it at https://gist.github.com/1971055.

share|improve this answer
1  
@jamaicanworm Please see edit. It works with fullwidth and vertical lines shortened. Please post a comment if this is ok, I will polish the code a bit and make it more user friendly. –  Yiannis Lazarides Mar 3 '12 at 19:22
1  
@jamaicanworm It actually looks awful with the parameters you specified for fullwidth:), that is also why we get the overful box. Line thickness etc... is easy to get. Do you have a scan of a sample of what you want perhaps from a book? The thickness of the lines is given by width is the same as before! –  Yiannis Lazarides Mar 3 '12 at 19:43
1  
@jamaicanworm Made the vrules shorter and thinner. If you want to change, try changing all the 20pt to something else. –  Yiannis Lazarides Mar 3 '12 at 19:54
1  
@jamaicanworm Thanks, will have a good look tomorrow for the overfull and the enviro. –  Yiannis Lazarides Mar 3 '12 at 20:37
1  
@jamaicanworm Please see link. –  Yiannis Lazarides Mar 4 '12 at 6:51
show 4 more comments

I am pretty sure TikZ will make an entry here, since it is much more proficient and decorative with these things. However, it is possible using a combination of rules to obtain this layout. I decided to use an environment rather than two separate macros, since it seemed to be more fitting - an environment allows for a start and end declaration.

enter image description here

\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}

The above MWE provides three environments, for the sake of difference (although they're virtually identical): separateA prints a "fully boxed" block, while separateB prints a "partially boxed" block (left and right) and separateC also a "partially boxed" block (right to left). Care is taken to make the horizontal separation be exactly \textblock+.4in wide, hanging over the edge by exactly .2in on either side.

It would be easy to construct a single environment (say) separate to do this, with optional arguments for control over the placements of the hangs/hungs.

showframe was used to highlight the text block boundary, and indicate and accentuate the overhang outside the text margin.

share|improve this answer
    
In the fullwidth environment, these vertical lines run off the page. Please see the EDIT to my question. I want the look of separateB, but is there a way to make the vertical lines taller? –  jamaicanworm Mar 3 '12 at 19:06
add comment
\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}

enter image description here

share|improve this answer
1  
Does \separate[up-and-down] also work? ;) –  Werner Mar 3 '12 at 15:47
    
In the fullwidth environment, these vertical lines run off the page. Please see the EDIT to my question. Also, when you zoom in, the vertical line looks slightly detached from the horizontal lines. Also also, might there be a way to make these lines thinner? –  jamaicanworm Mar 3 '12 at 19:08
1  
See edited example, it now uses \fboxrule. Change the value of 1.1\textwidth to your needs for the rule length. –  Herbert Mar 4 '12 at 9:17
add comment

Here is a Metapost solution (in ConTeXt). I define a MPbackground in metapost, that can then be plugged into any ConTeXt object that accepts a background parameter.

\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}]

As an example, consider adding a frame to a side float and a text background.

\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

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.