6

I want to trace a border in a box or minipage like this model. A border customizable in left angle on top and right angle in bottom. Somebody can help me? Thanks a lot JPierre

box

  • Welcome! What have you got so far? What kind of customisation do you want? – cfr Apr 26 '17 at 2:06
  • The easy solution is to use TikZ. One could also use \rule or picture to add the corners and a savebox to measure the width, height and depth. – John Kormylo Apr 26 '17 at 3:58
  • Another allround suggestion: tcolorbox. – TeXnician Apr 26 '17 at 4:25
  • Thanks a lot. I will try Tikz. You think its possible to make a framed pargraph with tikz and put the corner like the illustration? – Jean-Pierre Apr 26 '17 at 7:14
7

An inevitable answer with tcolorbox and defining some style keys: The ...lengths are calculated from the top left and bottom right corners, the colours are given as indicated.

\documentclass{article}

\usepackage{blindtext}

\usepackage[most]{tcolorbox}
\usetikzlibrary{calc}
\begin{document}

\tcbset{
  toplength/.store in={\tcbcornerruletoplength},
  leftlength/.store in={\tcbcornerruleleftlength},
  toplength=3cm,
  leftlength=2cm,
  bottomlength/.store in={\tcbcornerrulebottomlength},
  rightlength/.store in={\tcbcornerrulerightlength},
  bottomlength=3cm,
  rightlength=2cm,
  cornerruleshift/.store in={\tcbcornerruleshift},
  cornerruleshift=1pt,
  topcornercolor/.store in={\tcbtopcornercolor},
  bottomcornercolor/.store in={\tcbbottomcornercolor},
  topcornercolor=green!40!blue,
  bottomcornercolor=blue!40!green,
}

\newtcolorbox{cornerbox}[1][]{%
  enhanced jigsaw,
  sharp corners,
  boxrule=0pt,
  underlay={
    \coordinate (topend) at ($(frame.north west) + (0:\tcbcornerruletoplength)$);
    \coordinate (leftend) at ($(frame.north west) - (90:\tcbcornerruleleftlength)$);
    \coordinate (bottomend) at ($(frame.south east) - (0:\tcbcornerrulebottomlength)$);
    \coordinate (rightend) at ($(frame.south east) + (90:\tcbcornerrulerightlength)$);
    \draw[line width=2pt,\tcbtopcornercolor] ([xshift=-\tcbcornerruleshift]leftend) -- ([shift={(-\tcbcornerruleshift,\tcbcornerruleshift)}]frame.north west) -- ([shift={(-\tcbcornerruleshift,\tcbcornerruleshift)}] topend);
    \draw[line width=2pt,\tcbbottomcornercolor] ([xshift=\tcbcornerruleshift]rightend) -- ([shift={(\tcbcornerruleshift,-\tcbcornerruleshift)}]frame.south east) -- ([shift={(-\tcbcornerruleshift,-\tcbcornerruleshift)}] bottomend);
  },
  #1,
}


\begin{cornerbox}
\blindtext
\end{cornerbox}

\begin{cornerbox}[topcornercolor={yellow!40!red}]
\blindtext
\end{cornerbox}


\end{document}

enter image description here

Update with configurable colours and line widths:

\documentclass{article}

\usepackage{blindtext}

\usepackage[most]{tcolorbox}
\usetikzlibrary{calc}
\begin{document}

\tcbset{
  % Lengths of the rules
  northwestleft/.store in={\chnorthwestleftlength},
  southwestleft/.store in={\chsouthwestleftlength},
  northeastright/.store in={\chnortheastrightlength},
  southeastright/.store in={\chsoutheastrightlength},
  northwestleft=2cm,
  southwestleft=2cm,
  northeastright=2cm,
  southeastright=2cm,
  northleft/.store in={\chnorthleftlength},
  northright/.store in={\chnorthrightlength},
  southleft/.store in={\chsouthleftlength},
  southright/.store in={\chsouthrightlength},
  northleft=2cm,
  southleft=2cm,
  northright=2cm,
  southright=2cm,
  toplength/.forward to=/tcb/northright,
  toplength/.forward to=/tcb/northleft,
  leftlength/.forward to=/tcb/northwestleft,
  leftlength/.forward to=/tcb/southwestleft,
  rightlength/.forward to=/tcb/northeastright,
  rightlength/.forward to=/tcb/southeastright,
  bottomlength/.forward to=/tcb/southright,
  bottomlength/.forward to=/tcb/southleft,
  % Widths of the rules
  northwestleftrule/.store in={\chnorthwestleftrule},
  northwesttoprule/.store in={\chnorthwesttoprule},
  northwestrule/.forward to=/tcb/northwestleftrule,
  northwestrule/.forward to=/tcb/northwesttoprule,
  northeastrightrule/.store in={\chnortheastrightrule},
  northeasttoprule/.store in={\chnortheasttoprule},
  northeastrule/.forward to=/tcb/northeastrightrule,
  northeastrule/.forward to=/tcb/northeasttoprule,
  southwestleftrule/.store in={\chsouthwestleftrule},
  southwestbottomrule/.store in={\chsouthwestbottomrule},
  southwestrule/.forward to=/tcb/southwestleftrule,
  southwestrule/.forward to=/tcb/southwestbottomrule,
  southeastrightrule/.store in={\chsoutheastrightrule},
  southeastbottomrule/.store in={\chsoutheastbottomrule},
  southeastrule/.forward to=/tcb/southeastrightrule,
  southeastrule/.forward to=/tcb/southeastbottomrule,
  northwestleftrule=2pt,
  northwesttoprule=2pt,
  southwestleftrule=2pt,
  southwestbottomrule=2pt,
  northeastrightrule=2pt,
  northeasttoprule=2pt,
  southeastrightrule=2pt,
  southeastbottomrule=2pt,
  northrules/.forward to=/tcb/northwestrule,
  northrules/.forward to=/tcb/northeastrule,
  southrules/.forward to=/tcb/southwestrule,
  southrules/.forward to=/tcb/southeastrule,
  allrules/.forward to=/tcb/northrules,
  allrules/.forward to=/tcb/southrules,
  % Colours
  upperleftcolor/.store in={\chupperleftcolor},
  upperrightcolor/.store in={\chupperrightcolor},
  lowerrightcolor/.store in={\chlowerrightcolor},
  lowerleftcolor/.store in={\chlowerleftcolor},
  lowerleftcolor={blue},
  lowerrightcolor={blue},
  upperrightcolor={blue},
  upperleftcolor={blue},
  northcolor/.forward to=/tcb/upperleftcolor,
  northcolor/.forward to=/tcb/upperrightcolor,
  southcolor/.forward to=/tcb/lowerleftcolor,
  southcolor/.forward to=/tcb/lowerrightcolor,
  allcolors/.forward to=/tcb/northcolor,
  allcolors/.forward to=/tcb/southcolor,
  northwest/.style={%
    sharp corners=northwest,
    overlay app={
      \coordinate (north west corner) at ([shift={(-0.5*\chnorthwestleftrule,\chnorthwesttoprule)}]frame.north west);
      \coordinate (west start) at ([shift={(-0.5*\chnorthwestleftrule,-\chnorthwestleftlength)}]frame.north west);
      \coordinate (north end) at ([shift={(\chnorthleftlength,\chnorthwesttoprule))}]frame.north west);
      \draw[line width=\chnorthwestleftrule,\chupperleftcolor] (west start) -- (north west corner);
      \draw[line width=\chnorthwesttoprule,\chupperleftcolor] ([yshift={(-0.5*\chnorthwesttoprule)}]north west corner) -- ([yshift={(-0.5*\chnorthwesttoprule)}]north end);
    }
  },
  southeast/.style={
    sharp corners=southeast,
    overlay app={
      \coordinate (south east corner)   at ([shift={(0.5*\chsoutheastrightrule,-\chsoutheastbottomrule)}]frame.south east);
      \coordinate (east end) at ([shift={(-\chsouthrightlength,-\chsoutheastbottomrule)}]frame.south east);
      \coordinate (east start)  at ([shift={(0.5*\chsoutheastrightrule,\chsoutheastrightlength)}]frame.south east);
      \draw[line width=\chsoutheastrightrule,\chlowerrightcolor] (east start) -- (south east corner);
      \draw[line width=\chsoutheastbottomrule,\chlowerrightcolor] ([yshift={(0.5*\chsoutheastbottomrule)}]south east corner) -- ([yshift={(0.5*\chsoutheastbottomrule)}]east end);
    }
  },    
  northeast/.style={
    sharp corners=northeast,
    overlay app={
      \coordinate (north east corner)   at ([shift={(0.5*\chnortheastrightrule,\chnortheasttoprule)}]frame.north east);
      \coordinate (north start)  at ([shift={(0.5*\chnortheastrightrule,-\chnortheastrightlength)}]frame.north east);
      \coordinate (north end) at ([shift={(-\chnorthrightlength,\chnortheasttoprule))}]frame.north east);
      \draw[line width=\chnortheastrightrule,\chupperrightcolor] (north start) -- (north east corner);
      \draw[line width=\chnortheasttoprule,\chupperrightcolor] ([yshift={(-0.5*\chnortheasttoprule)}]north east corner) --  ([yshift={(-0.5*\chnortheasttoprule)}]north end);
    }
  },
  southwest/.style={
    sharp corners=southwest,
    overlay app={
      \coordinate (south west corner)   at ([shift={(-0.5*\chsouthwestleftrule,-\chsouthwestbottomrule)}]frame.south west);
      \coordinate (south start)  at ([shift={(-0.5*\chsouthwestleftrule,\chsouthwestleftlength)}]frame.south west);
      \coordinate (south end) at ([shift={(\chsouthleftlength,-\chsouthwestbottomrule)}]frame.south west);
      \draw[line width=\chsouthwestleftrule,\chlowerleftcolor] (south start) -- (south west corner);
      \draw[line width=\chsouthwestbottomrule,\chlowerleftcolor] ([yshift={(0.5*\chsouthwestbottomrule)}]south west corner) -- ([yshift={(0.5*\chsouthwestbottomrule)}]south end);
    }
  },
  northwestsoutheast/.style={overlay={},northwest,southeast},
  northeastsouthwest/.style={overlay={},northeast,southwest},
  allcorners/.style={overlay={},northeastsouthwest,northwestsoutheast},
}


\newtcolorbox{cornerbox}[1][]{%
  enhanced jigsaw,
  boxrule=0pt,
  northwestsoutheast,
  #1
}


\makeatother


\begin{cornerbox}[northeastsouthwest,allcolors=yellow!20!red,allrules=2pt]
\blindtext
\end{cornerbox}

\begin{cornerbox}[allcolors=green!40!blue,northwestleftrule=5pt]
\blindtext
\end{cornerbox}


\end{document}

enter image description here

6

Here I just stack some rules around a colored \parbox. Syntax is

\specialbox{<box-color>}{<frame-color>}{<frame-length>}{<box-width>}{<content>}

It can be used inline or as its own paragraph. The values of \fboxsep and \fboxrule are obeyed. Being a box, it does not break across pages.

Here is the MWE.

\documentclass{article}
\usepackage{xcolor,stackengine,lipsum}
\newcommand\specialbox[5]{%
  \kern\fboxrule%
  \stackinset{r}{}{b}{0pt}{\color{#2}\rule{\fboxrule}{#3}}{%
  \stackinset{r}{}{b}{-\fboxrule}{\color{#2}\rule{#3}{\fboxrule}}{%
  \stackinset{l}{-\fboxrule}{t}{0pt}{\color{#2}\rule{\fboxrule}{#3}}{%
  \stackinset{l}{-\fboxrule}{t}{-\fboxrule}{\color{#2}\rule{#3}{\fboxrule}}{%
  \colorbox{#1}{\parbox{\dimexpr#4-2\fboxsep-2\fboxrule}{#5}}%
  }}}%
  \kern\fboxrule}%
}
\begin{document}
\lipsum[1]

\fboxrule=3pt\relax%
\noindent\specialbox{yellow!95!orange}{yellow!50!orange}{40pt}{\linewidth}{\lipsum[3]}

\lipsum[2]

\fboxsep=10pt\relax\fboxrule=5pt\relax%
Testing\specialbox{cyan!10}{red}{50pt}{3in}{\lipsum[4]}inline
\end{document}

enter image description here

  • GREAT. Its exactly the model I want to use. I will adapt this code. Thanks a lot for your answer. JPierre – Jean-Pierre Apr 27 '17 at 13:42
  • @Jean-Pierre You are welcome. Whichever of the several answers best provides what you are looking for in an answer, consider clicking the check mark to the left of the best answer to "accept" it. This will give some tangible credit to the provider of the answer and also indicate to future readers of your question what approach at a resolution you found most helpful. – Steven B. Segletes Apr 28 '17 at 0:44

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.