27

How can I add vertical lines to each side of a paragraph?

To illustrate, what I need is:

 some paragraphs...

|My paragraph begins|
|here and goes like |
|this... ~~~~~~~~~~~|
|~~~~~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~~~~~|
--------------------- <- Here is a page break
|~~~~~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~~~~~|
|The paragraph ends |
|here.              |

Some other paragraphs...

I could not use any tabular or boxing commands since they don't allow page breaks inside.

Thanks in advance...

Alper
  • 477

2 Answers2

33

You can use the mdframed package; a little example:

\documentclass{article}
\usepackage{mdframed}
\usepackage{lipsum}% just to generate text for the example

\newmdenv[
  topline=false,
  bottomline=false,
  skipabove=\topsep,
  skipbelow=\topsep
]{siderules}

\begin{document}

\lipsum[4]
\begin{siderules}
\lipsum[1-5]
\end{siderules}
\lipsum[4]

\end{document}

enter image description here

Here's a simplemodification placing the rules in the margin (now the text width inside the environment is equal to the default \textwidth):

\documentclass{article}
\usepackage{mdframed}
\usepackage{lipsum}% just to generate text for the example

\newmdenv[
  topline=false,
  bottomline=false,
  skipabove=\topsep,
  skipbelow=\topsep,
  leftmargin=-10pt,
  rightmargin=-10pt,
  innertopmargin=0pt,
  innerbottommargin=0pt
]{siderules}

\begin{document}

\lipsum[4]
\begin{siderules}
\lipsum[1-5]
\end{siderules}
\lipsum[4]

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
12

With results similar to Gonzalo's answer but made with tcolorbox.

\documentclass{article}
\usepackage{lipsum}% just to generate text for the example

\usepackage[most]{tcolorbox}

\newtcolorbox{tcbsiderules}[1][]{blanker, breakable, 
     left=3mm, right=3mm, top=1mm, bottom=1mm,
     borderline vertical={1pt}{0pt}{black},
     before upper=\indent, parbox=false, #1}


\begin{document}

\lipsum[1]
\begin{tcbsiderules}[oversize]
\lipsum[2-4]
\end{tcbsiderules}
\begin{tcbsiderules}
\lipsum[5-7]
\end{tcbsiderules}
\lipsum[8]

\end{document}

enter image description here

Ignasi
  • 136,588
  • I get the error: I do not know the key '/tcp/borderline vertical', to which you passed '{1pt}{0pt}{black}', and I am going to ignore it. Perhaps you misspelled it. – Jonathan Komar Jul 27 '15 at 12:00
  • @macmadness86 You need to update tcolorbox. According its documentation, borderline vertical was added on 20-Oct-2014. – Ignasi Jul 27 '15 at 16:02
  • Ok I see. I will probably not be able to use your option then, because I unfortunately cannot update the system (yet). Thanks for identifying the problem though! – Jonathan Komar Jul 27 '15 at 16:34
  • @macmadness86: If you don't want to update your system, just install tcoorbox.sty and ...code.tex files from ctan in your working folder. It's not the correct solution, but will work until you update the system. – Ignasi Jul 27 '15 at 17:51
  • more footnote friendly than mdframe, though it supercedes the footnote system by moving them at the end of the box (and thus uses a letter system to avoid confusions) – Arnaud Dec 20 '16 at 17:33