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...

2
  • 1
    do you want the vertical lines in the margin or as in Gonzalo's answer inside the text area?
    – user4686
    Dec 10, 2012 at 16:43
  • 3
    @jfbu my answer now includes both options. Dec 10, 2012 at 17:24

2 Answers 2

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

8
  • 1
    the first paragraphs in both cases are not indented, is this an after-effect of the use of mdframed?
    – user4686
    Dec 10, 2012 at 17:29
  • 1
    @jfbu yes, apparently the first line of the first paragraph is not indented by design. Dec 10, 2012 at 17:37
  • 3
    @jfbu to get the first line indented, one can add \mbox{}\indent right after \begin{siderules}. Dec 10, 2012 at 17:49
  • That's what I was really looking for. Thank you so much..
    – Alper
    Dec 11, 2012 at 12:22
  • 1
    does not seem to be compatible with footnotes
    – Arnaud
    Dec 20, 2016 at 17:29
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

5
  • 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. Jul 27, 2015 at 12:00
  • @macmadness86 You need to update tcolorbox. According its documentation, borderline vertical was added on 20-Oct-2014.
    – Ignasi
    Jul 27, 2015 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! Jul 27, 2015 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, 2015 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, 2016 at 17:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .