Rand in einem Kastenrahmen oder einer Miniseite

Rand in einem Kastenrahmen oder einer Miniseite

Ich möchte einen Rahmen in einer Box oder Miniseite wie diesem Modell zeichnen. Ein Rahmen, der oben links und unten rechts anpassbar ist. Kann mir jemand helfen? Vielen Dank, JPierre

Kasten

Antwort1

Hier stapele ich einfach ein paar Regeln um ein farbiges \parbox. Die Syntax ist

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

Es kann inline oder als eigener Absatz verwendet werden. Die Werte von \fboxsepund \fboxrulewerden beachtet. Da es sich um eine Box handelt, wird es nicht über mehrere Seiten verteilt.

Hier ist das 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}

Bildbeschreibung hier eingeben

Antwort2

Eine unvermeidliche Antwort mit tcolorboxund Definition einiger Stilschlüssel: Sie ...lengthswerden aus der oberen linken und unteren rechten Ecke berechnet, die Farben werden wie angegeben angegeben.

\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}

Bildbeschreibung hier eingeben

Aktualisierenmit konfigurierbaren Farben und Linienbreiten:

\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}

Bildbeschreibung hier eingeben

verwandte Informationen