2

Using mdframed we can opt out any of the four bounding lines. But what I want is, both the vertical lines will be present, but instead of top and bottom lines, I need a partial line at top-left and another partial line at bottom-right. The following is the code I have tried so far:

\documentclass{article}

\usepackage[framemethod=tikz]{mdframed}

\usepackage{lipsum}

\begin{document}

\mdfdefinestyle{myboxstyle}{%
  rightline=true,
  innerleftmargin=10,
  innerrightmargin=10,
  linecolor=gray,
  outerlinewidth=1.0mm,
  topline=false,
  rightline=true,
  bottomline=false,
  skipabove=\topsep,
  skipbelow=\topsep
}

\begin{mdframed}[style=myboxstyle]
  \lipsum[1]
\end{mdframed}

\end{document}

The above produces the following image where the lines at top and bottom are the ones I failed to get.

enter image description here

6

Here's a tcolorbox version. Just adjust the 2cm to your liking.

tcb

\documentclass{article}
\usepackage[skins]{tcolorbox}

\newtcolorbox{mybox}{enhanced,sharp corners=all,colback=white,colframe=gray,toprule=0pt,bottomrule=0pt,leftrule=1pt,rightrule=1pt,overlay={
    \draw[gray,line width=1pt] (frame.north west) -- ++(2cm,0pt);
    \draw[gray,line width=1pt] (frame.south east) -- ++(-2cm,0pt);
}}

\usepackage{lipsum}

\begin{document}

    \begin{mybox}
      \lipsum[2]
    \end{mybox}

\end{document}

Update: Title addition. To put more distance between title and text just use bottom=1pt (or more) in boxed title style.

with title

\documentclass{article}
\usepackage[skins]{tcolorbox}

\newtcolorbox{mybox}[1]{enhanced,sharp corners=all,colback=white,colframe=gray,toprule=0pt,bottomrule=0pt,leftrule=1pt,rightrule=1pt,overlay={
    \draw[gray,line width=1pt] (frame.north west) -- ++(2cm,0pt);
    \draw[gray,line width=1pt] (frame.south east) -- ++(-2cm,0pt);
},attach boxed title to top left,boxed title style={frame hidden,interior hidden},title={\color{black}#1}}

\usepackage{lipsum}

\begin{document}

    \begin{mybox}{Test}
      \lipsum[2]
    \end{mybox}

\end{document}

Update 2: If you have a boxed title which is of only one line height you could be interested in this hack:

title within

\documentclass{article}
\usepackage[skins]{tcolorbox}

\newtcolorbox{mybox}[1]{enhanced,sharp corners=all,colback=white,colframe=gray,toprule=0pt,bottomrule=0pt,leftrule=1pt,rightrule=1pt,overlay={
    \draw[gray,line width=1pt] (frame.north west) -- ++(2cm,0pt);
    \draw[gray,line width=1pt] (frame.south east) -- ++(-2cm,0pt);
},attach boxed title to top left={yshift=-20pt},boxed title style={frame hidden,interior hidden},top=.75cm,title={\bfseries\color{black}#1}}

\usepackage{lipsum}

\begin{document}

    \begin{mybox}{Test}
      \lipsum[2]
    \end{mybox}

\end{document}

Update 3: Here's the "correct" way to change the title height.

title inner

\documentclass{article}
\usepackage[skins]{tcolorbox}

\newtcolorbox{mybox}[1]{enhanced,sharp corners=all,colback=white,colframe=gray,toprule=0pt,bottomrule=0pt,leftrule=1pt,rightrule=1pt,overlay={
            \draw[gray,line width=1pt] (frame.north west) -- ++(2cm,0pt);
            \draw[gray,line width=1pt] (frame.south east) -- ++(-2cm,0pt);
    },
    coltitle=black,colbacktitle=white,titlerule=0pt,
    title={\vskip5pt\bfseries#1}
}

\usepackage{lipsum}

\begin{document}

    \begin{mybox}{This is a very long title which seems pretty ridiculous, but is used, although it is nonsense}
      \lipsum[2]
    \end{mybox}

\end{document}
  • Thanks. Is it possible to put a title (without any background color) without messing with the line at top-left? – Masroor Aug 8 '17 at 17:48
  • @Masroor Added an example. – TeXnician Aug 8 '17 at 17:56
  • Perhaps I am stretching the limit, but what if I want to put the title below the line at top-left? That means the title will be inside the whole frame. – Masroor Aug 8 '17 at 18:02
  • I found a quick hack of putting the title as the upper text, and the body text after \tcblower. I need to use segmentation empty, so that \tcbline is not drawn. – Masroor Aug 8 '17 at 18:29
  • Or we can use lower separated=false in the above hack. But I will wait for the final words from you. – Masroor Aug 8 '17 at 18:33

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.