3

I'm looking for a way to draw a border on the top and left, but they should have different widths. I've been trying to do this using the mdframed package, but there doesn't seem to be an easy way to draw a border on the left that has a different width from the border at the top.

\documentclass{article}
\usepackage{mdframed}
\usepackage{lipsum}

\newmdenv[rightline=false,bottomline=false]{topbot}

\begin{document}

\begin{topbot}
\subsection*{This is the title}
\end{topbot}
\lipsum[2]

\end{document}

This is what I have:

Border with wrong width

And this is what I am looking for:

right border

  • Do you want to get text boxes with this format? or Do you want to get section and subsection titles with this format? – Ignasi Nov 29 '16 at 10:20
  • @Ignasi: I am after text boxes. See my updated question. – user Nov 29 '16 at 14:02
4

Although I think this is not the way to change section format, here you have a solution for OP's example with tcolorbox.

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}

\newtcolorbox{topbot}[1][]{leftrule=5pt, toprule=.5pt, rightrule=0pt, bottomrule=0pt, colback=white, notitle, sharp corners, #1}

\begin{document}

\begin{topbot}
\subsection*{This is the title}
\end{topbot}
\lipsum[2]

\end{document}

enter image description here

Update:

If a fancy format for unnumbered sections is what is desired. titlesec provides better solutions than a mdframed or tcolorbox environment containing a subsection command.

\documentclass{article}
\usepackage{xcolor}
\usepackage[calcwidth,explicit]{titlesec}
\usepackage{lipsum}

\titleformat{name=\subsection, numberless}
  {\titlerule\normalfont\large\bfseries}
  {\colorbox{black}{\parbox{1mm}{\strut}}}
  {.5em}{#1}

\titlespacing*{\subsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\begin{document}

\subsection*{This is the title}

\lipsum[2]

\end{document}

enter image description here

  • Thanks a lot! But there are two issues... I don't need this to be section-specific so I ran your first MWE but a) the color is a light grey, not black, without this being specified, and b) there is a box AROUND the whole block (so also at the bottom and right hand side). I will show a screenshot in my post, as I don't know how to add it in a comment. – user Nov 29 '16 at 13:52
  • Actually, let me post a new question so this stays on topic and the whole thing doesn't get too complicated. I'll accept this answer and post a separate question for my second inquiry. Thanks! – user Nov 29 '16 at 15:59

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.