3

I'm looking for a way to have double vertical lines along the left side of a paragraph. It can be done by framed package, but I don't like its spacing (see picture.) The aim is that tcolorbox produces, but I don't like to use TikZ because it slows down compilation (I will use rule frequently.)

I saw This question, which asked a way to produce breakable vertical rule in Plain TeX, but the spacing is like one by framed. I also tried mdframed package (without TikZ), but it produced boxes like framed and double lines are not supported (without TikZ or PSTricks.)

So how can it be done without TikZ?

Thanks

Output

framed vs tcolorbox The lines are page frames obtained by showframe.

Difference (Added)

  • 'With framed' has space between top frame and has no space between bottom.
  • 'With tcolorbox' has no space between top and has space between bottom. In other words, the line ends precisely at the place where the content ends.

Code

\documentclass{article}

\usepackage{framed}

\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{xparse,skins,breakable}

\usepackage{lipsum}
\usepackage{showframe}

\newenvironment{leftvert}{%
    \def\FrameCommand{%
        \kern 1.75pt \vrule width 1.9pt \kern .7pt \vrule width 1.9pt\hspace{\dimexpr 2em-6.25pt}%
    } \MakeFramed {\advance\hsize-\width \FrameRestore}%
}{\endMakeFramed}

\newtcolorbox{tleftvert}{%
    parbox=false,
    breakable,
    blanker,
    left=2em,
    borderline west={2pt}{3pt}{double},
}

\begin{document}
    \begin{leftvert}
        \lipsum[1-10]
    \end{leftvert}
    \begin{tleftvert}
        \par
        \lipsum[1-10]
    \end{tleftvert}
\end{document}

Another example (Added)

javi_gg1 wrote:

The way I see it, in both cases the rule begins and ends exactly where the text begins and ends. The difference is that, with tcolorbox, both text and rule are aligned to the top of the page frame, while with framed both are aligned to the bottom of the page frame.

I give another example to show it's not true.

Edit: I put this example here so that we can easy to see wrong bottom spacing. So I still have wrong spacing with texts without math.

framed vs tcolorbox

\begin{document}
    \begin{leftvert}
        \lipsum[1-3]
        \newpage
        \begin{equation}
            \begin{split}
                some &= long\\ &= long\\ &= long\\ &= long\\ &= long\\ &= long\\
                     &= long\\ &= long\\ &= long\\ &= long\\ &= long\\ &= long\\
                     &= equation.
            \end{split}
        \end{equation}
    \end{leftvert}
    \newpage
    \begin{tleftvert}
        \par
        \lipsum[1-3]
        \begin{equation}
            \begin{split}
                some &= long\\ &= long\\ &= long\\ &= long\\ &= long\\ &= long\\
                     &= long\\ &= long\\ &= long\\ &= long\\ &= long\\ &= long\\
                     &= equation.
            \end{split}
        \end{equation}
    \end{tleftvert}
\end{document}
  • 1
    You can add the blankest option to your boxes and then drawing of frames will omitted and remove the option later on in the final release – user31729 Dec 23 '17 at 15:48
  • What's the real difference between the framed and the tcolorbox solution? I can't perceive it, as the figures are scaled differently. – Bernard Dec 23 '17 at 15:54
  • @Bernard I added an explanation. – B. W. Dec 23 '17 at 16:04
  • @B.W. As a comment, the way I see it, in both cases the rule begins and ends exactly where the text begins and ends. The difference is that, with tcolorbox, both text and rule are aligned to the top of the page frame, while with framed both are aligned to the bottom of the page frame. – javi_gg1 Dec 23 '17 at 18:35
6

The way I see it, in both cases the rule begins and ends exactly where the text begins and ends. The difference is that, with tcolorbox, both text and rule are aligned to the top of the page frame, while with framed both are aligned to the bottom of the page frame.

When using a framed environment, the distance between the baseline of the first line of text and the top of the page can be set by adjusting the value of \FrameHeightAdjust. Setting it to a little bit less than 1em should achieve your desired effect (using exactly 1em makes it overfill the page and create a blank page at the beginning):

\renewcommand{\FrameHeightAdjust}{\dimexpr 1em-0.1pt}

frames

\documentclass{article}

\usepackage{framed}

\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{xparse,skins,breakable}

\usepackage{lipsum}
\usepackage{showframe}

\newenvironment{leftvert}{%
    \renewcommand{\FrameHeightAdjust}{\dimexpr 1em-0.1pt}
    \def\FrameCommand{%
        \kern 1.75pt \vrule width 1.9pt \kern .7pt \vrule width 1.9pt\hspace{\dimexpr 2em-6.25pt}%
    } \MakeFramed {\advance\hsize-\width \FrameRestore}%
}{\endMakeFramed}

\newtcolorbox{tleftvert}{%
    parbox=false,
    breakable,
    blanker,
    left=2em,
    borderline west={2pt}{3pt}{double},
}

\begin{document}
    \begin{leftvert}
        \lipsum[1-10]
    \end{leftvert}
    \begin{tleftvert}
        \par
        \lipsum[1-10]
    \end{tleftvert}
\end{document}

Edit: if you use a \newpagecommand inside a framed environment, the rule will extend to the bottom of the page. To prevent this, you can close the framed environment, issue the \newpagecommand, and open the framed environment again:

...
\end{leftvert}
\newpage
\begin{leftvert}
...

As for equations, they inherently have some padding above and below, which makes the rule extend longer. If you happen to have an equation at the end of your framed environment and you want the rule to end where the equation ends, you can locally set \belowdisplayskip to 0pt:

{
\setlength{\belowdisplayskip}{0pt}
    \begin{equation}
    ....
    \end{equation}
}

Note the enclosing braces that make the change local: you still want to have the padding in other equations.

framed newpage framed equation

\documentclass{article}

\usepackage{amsmath}

\usepackage{framed}

\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{xparse,skins,breakable}

\usepackage{lipsum}
\usepackage{showframe}

\renewcommand{\FrameHeightAdjust}{\dimexpr 1em-0.1pt}
\newenvironment{leftvert}{%
    \def\FrameCommand{%
        \kern 1.75pt \vrule width 1.9pt depth 0pt \kern .7pt \vrule width 1.9pt depth 0pt\hspace{\dimexpr 2em-6.25pt}%
    } \MakeFramed {\advance\hsize-\width \FrameRestore}%
}{\endMakeFramed}

\newtcolorbox{tleftvert}{%
    parbox=false,
    breakable,
    blanker,
    left=2em,
    borderline west={2pt}{3pt}{double},
}

\begin{document}
    \begin{leftvert}
        \lipsum[1-3]
    \end{leftvert}
    \newpage
    \begin{leftvert}
        {
        \setlength{\belowdisplayskip}{0pt}
        \begin{equation}
        \begin{split}
        some &= long\\ &= long\\ &= long\\ &= long\\ &= long\\ &= long\\
        &= long\\ &= long\\ &= long\\ &= long\\ &= long\\ &= long\\
        &= equation.
        \end{split}
        \end{equation}
    }
    \end{leftvert}
    \newpage
    \begin{tleftvert}
        \par
        \lipsum[1-3]
        \begin{equation}
        \begin{split}
        some &= long\\ &= long\\ &= long\\ &= long\\ &= long\\ &= long\\
        &= long\\ &= long\\ &= long\\ &= long\\ &= long\\ &= long\\
        &= equation.
        \end{split}
        \end{equation}
    \end{tleftvert}
\end{document}
  • Thanks for fixing top spacing, but bottom spacing is still wrong. See an added example. – B. W. Dec 24 '17 at 4:02
  • @B.W. See my edit: I added a workaround for the \newpage and the equation cases. – javi_gg1 Dec 24 '17 at 13:18
  • The code I added is just an example which we can easy to see wrong bottom spacing. So I still have wrong spacing with texts without math. – B. W. Dec 24 '17 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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