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.

At the moment I'm using the {tabular} environment to distinguish examples in a document I'm writing:

\begin{tabular}{r|p{11cm}}
\emph{Example} & [Lots of text and equations]
\end{tabular}

It makes it so that there's a nice line running down the left side of my page over the course of the example. The only problem is that it doesn't behave well with page breaks. I know the package longtable works for continuing tables onto several pages but since I have everything in one table entry, it doesn't work for me.

I realise I'm completely misusing {tabular} and am looking for an environment that will give me the same effect, but will continue the effect onto successive pages.

share|improve this question
    
mdframed is the only way to go for this kind of thing- I think you'll find what you're looking for in, for example, How to choose which sides of the border to draw in a framebox? –  cmhughes Jul 24 '13 at 20:20

2 Answers 2

Two simple examples showing two possibilities: one with mdframed and the other one with tcolorbox; the advantage of these packages over framed is that they offer endless customization possibilities with a simple key=value interface:

\documentclass{article}
\usepackage[a5paper,paperwidth=18cm]{geometry}% just for the example
\usepackage{amsthm}
\usepackage[framemethod=tikz]{mdframed}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}% just to generate text for the example

\newmdtheoremenv[
hidealllines=true,
leftline=true,
innertopmargin=0pt,
innerbottommargin=0pt,
linewidth=4pt,
linecolor=gray!40,
innerrightmargin=0pt,
innertopmargin=-6pt,
]{examplei}{Example}

\newtcolorbox{exampleii}{
freelance,
breakable,
width=\dimexpr\textwidth+28pt\relax,
before=\par\vspace{\bigskipamount}\noindent,
enlarge left by=-14pt,
overlay unbroken and first={
  \node[
  anchor=north east,
  inner xsep=8pt,
  xshift=8pt,
  rounded corners=5pt,
  font=\bfseries,
  fill=white] at ([xshift=-0.2cm]frame.north west) (tit) {\strut Example:};
  \draw[
  line width=3pt,
  rounded corners=5pt,gray
  ] ([xshift=4pt]frame.north west) -- ([xshift=4pt]frame.south west);
},
overlay middle and last={
  \draw[
  line width=3pt,
  rounded corners=5pt,gray
  ] ([xshift=4pt]frame.north west) -- ([xshift=4pt]frame.south west);
},
frame code={},
interior code={},
top=0pt,
bottom=0pt
}

\begin{document}

\lipsum[1]
\begin{examplei}
\lipsum[4]
\end{examplei}
\lipsum[4]
\begin{examplei}
\lipsum[1-2]
\end{examplei}
\lipsum[1-3]
\begin{exampleii}
\lipsum[4]
\end{exampleii}
\lipsum[1]
\begin{exampleii}
\lipsum[4-6]
\end{exampleii}
\lipsum[4-5]

\end{document}

enter image description here

The page layout was changed just for the example.

You can also take a look at the answer to Typesetting a definition for more examples and variations (the code in that answer can be easily adapted to produce the label "Example" instead of "Definition").

share|improve this answer

MWE using the package framed, edited to have enough text to break the page:

\documentclass{article}


\usepackage{framed}
\newenvironment{example}%
{\begin{leftbar}\begin{quotation}}%
{\end{quotation}\end{leftbar}}

\usepackage{lipsum}

\begin{document}
\lipsum[1-2]

\begin{example}
\lipsum[1-10]
\end{example}

\end{document}

Want to change how thick your line is and how far from your text it's set? Add this to the preamble after you \usepackage{framed}:

\renewenvironment{leftbar}{%
  \def\FrameCommand{\vrule width 1pt \hspace{5pt}}%
  \MakeFramed {\advance\hsize-\width \FrameRestore}}%
 {\endMakeFramed}

where \vrule width Xpt (in this case, changed to 1pt) sets the thickness of your vertical rule and \hspace{Ypt}, set to 5pt here, is the space from your line to your text.

You can also use the native leftbar environment if you don't want to deal with the other formating that comes with the quotation environment. Just frame your example text with

\begin{leftbar}
\lipsum[1-10]
\end{leftbar}

and the same customization options in the preamble will apply.

share|improve this answer

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.