盒子的边角更圆润,但倒置

盒子的边角更圆润,但倒置

我长期使用 LaTeX,最近我需要一些我自己无法解决的问题,因此我很感激任何人的时间和帮助。

我需要一个带圆角的盒子,这很容易做到 - 例如,这个线程显示了如何: 如何绘制带有圆角的框

我使用mdframed环境来完成此操作。但是,现在我想反转圆角,使圆心位于框的角落。实际上,我想实现的是:

在此处输入图片描述

但我不知道该怎么做,所以我想寻求你的帮助。

提前致谢。

答案1

代码行可以减少,但这里使用tcolorbox

\documentclass{scrbook}
\usepackage{lipsum}
\usepackage{tcolorbox}

\tcbuselibrary{skins}
\usetikzlibrary{calc}
\pgfdeclarelayer{foreground}
\pgfsetlayers{main,foreground}

\newtcolorbox{mybox}{
  colback=red!5!white,
  %width=\linewidth/2, Change the width 
  left=20pt, % left space between content text and box
  top=20pt,
  bottom=20pt,
  right=20pt,
  skin=freelance,
  frame code={%
    \begin{pgfonlayer}{foreground}  
    \draw[line width = 2pt,color = blue!30] ($(frame.south west) +(-4pt,-4pt)$) rectangle ($(frame.north east)+(4pt,4pt)$); %% outer rectangle
    \clip (frame.south west) rectangle (frame.north east);
    \draw[line width = 2pt,color=red!75!black,fill = white] (frame.south west) circle (25pt);
    \draw[line width = 2pt,color=red!75!black,fill = white] (frame.north west) circle (25pt);
    \draw[line width = 2pt,color=red!75!black,fill = white] (frame.north east) circle (25pt);
    \draw[line width = 2pt,color=red!75!black,fill = white] (frame.south east) circle (25pt);
      \draw[line width = 4pt,color=red!75!black]
           ($(frame.south west) +(0pt,24pt)$) -- ($(frame.north west)+(0pt,-24pt)$)  ; %% west
      \draw[line width = 4pt,color=red!75!black]
           ($(frame.north west) +(24pt,0pt)$) -- ($(frame.north east)+(-24pt,0pt)$)  ; %% north
      \draw[line width = 4pt,color=red!75!black]
           ($(frame.north east) +(0pt,-24pt)$) -- ($(frame.south east)+(0pt,24pt)$)  ; %% east
      \draw[line width = 4pt,color=red!75!black]
           ($(frame.south west) +(24pt,0pt)$) -- ($(frame.south east)+(-24pt,0pt)$)  ; %% south      
    \end{pgfonlayer}
  },
}

\begin{document}

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

\end{document}

在此处输入图片描述

答案2

使用并允许分页符的解决方案mdframed;只需更改值\myRad即可获得不同的分隔符和弧半径的值:

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

\newlength\myRad
\setlength\myRad{20pt}

\newmdenv[
settings={\tikzset{line cap=rect}},
innerrightmargin=2\myRad,
innerleftmargin=2\myRad,
innertopmargin=2\myRad,
innerbottommargin=2\myRad,
singleextra={
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=-\myRad,xshift=2\myRad]P-|O) -- ([yshift=-\myRad,xshift=-2\myRad]P);
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=-2\myRad,xshift=-\myRad]P) -- ([yshift=2\myRad,xshift=-\myRad]P|-O);
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=2\myRad,xshift=\myRad]O) -- ([yshift=-2\myRad,xshift=\myRad]O|-P);
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=\myRad,yshift=-2\myRad]P-|O) arc[start angle=-90,end angle=0] (P-|O); 
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=-\myRad,yshift=-2\myRad]P) arc[start angle=270,end angle=180] (P); 
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=\myRad,xshift=2\myRad]O) -- ([yshift=\myRad,xshift=-2\myRad]P|-O);
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=\myRad,yshift=2\myRad]O) arc[start angle=90,end angle=0] (O); 
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=-\myRad,yshift=2\myRad]P|-O) arc[start angle=90,end angle=180] (P|-O); 
  },
middleextra={
  \draw[gray!30,line width=5pt,line cap=rect] ([xshift=-\myRad]P) -- ([xshift=-\myRad]P|-O);
  \draw[gray!30,line width=5pt,line cap=rect] ([xshift=\myRad]O) -- ([xshift=\myRad]O|-P);
  },
firstextra={
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=-\myRad,xshift=2\myRad]P-|O) -- ([yshift=-\myRad,xshift=-2\myRad]P);
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=-2\myRad,xshift=-\myRad]P) -- ([xshift=-\myRad]P|-O);
  \draw[gray!30,line width=5pt,line cap=rect] ([xshift=\myRad]O) -- ([yshift=-2\myRad,xshift=\myRad]O|-P);
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=\myRad,yshift=-2\myRad]P-|O) arc[start angle=-90,end angle=0] (P-|O); 
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=-\myRad,yshift=-2\myRad]P) arc[start angle=270,end angle=180] (P); 
  },
secondextra={
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=\myRad,xshift=2\myRad]O) -- ([yshift=\myRad,xshift=-2\myRad]P|-O);
  \draw[gray!30,line width=5pt,line cap=rect] ([xshift=-\myRad]P) -- ([yshift=2\myRad,xshift=-\myRad]P|-O);
  \draw[gray!30,line width=5pt,line cap=rect] ([yshift=2\myRad,xshift=\myRad]O) -- ([xshift=\myRad]O|-P);
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=\myRad,yshift=2\myRad]O) arc[start angle=90,end angle=0] (O); 
  \draw[radius=\myRad,gray!30,line width=5pt,line cap=rect] ([xshift=-\myRad,yshift=2\myRad]P|-O) arc[start angle=90,end angle=180] (P|-O); 
  }
]{invcor}

\begin{document}

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

\begin{invcor}
\lipsum[1-7]
\end{invcor}

\end{document}

在此处输入图片描述

更新:

我引入了三个 mdf 键myRadmyLineWd和 ,myLineColor允许您进一步自定义属性(当然,框架仍然允许分页符):

\documentclass[dvipsnames]{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

\makeatletter
\newlength\mdf@@myRad
\newlength\mdf@@myLineWd
\define@key{mdf}{myRad}{\global\setlength\mdf@@myRad{#1}}
\define@key{mdf}{myLineWd}{\global\setlength\mdf@@myLineWd{#1}}
\define@key{mdf}{myLineColor}{\global\def\mdf@@myLineColor{#1}}

\newmdenv[
myRad=20pt,
myLineWd=5pt,
myLineColor=gray!30,
innerrightmargin=2\mdf@@myRad,
innerleftmargin=2\mdf@@myRad,
innertopmargin=2\mdf@@myRad,
innerbottommargin=2\mdf@@myRad,
singleextra={
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=-\mdf@@myRad,xshift=2\mdf@@myRad]P-|O) -- ([yshift=-\mdf@@myRad,xshift=-2\mdf@@myRad]P);
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=-2\mdf@@myRad,xshift=-\mdf@@myRad]P) -- ([yshift=2\mdf@@myRad,xshift=-\mdf@@myRad]P|-O);
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=2\mdf@@myRad,xshift=\mdf@@myRad]O) -- ([yshift=-2\mdf@@myRad,xshift=\mdf@@myRad]O|-P);
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=\mdf@@myRad,yshift=-2\mdf@@myRad]P-|O) arc[start angle=-90,end angle=0] (P-|O); 
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=-\mdf@@myRad,yshift=-2\mdf@@myRad]P) arc[start angle=270,end angle=180] (P); 
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=\mdf@@myRad,xshift=2\mdf@@myRad]O) -- ([yshift=\mdf@@myRad,xshift=-2\mdf@@myRad]P|-O);
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=\mdf@@myRad,yshift=2\mdf@@myRad]O) arc[start angle=90,end angle=0] (O); 
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=-\mdf@@myRad,yshift=2\mdf@@myRad]P|-O) arc[start angle=90,end angle=180] (P|-O); 
  },
middleextra={
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([xshift=-\mdf@@myRad]P) -- ([xshift=-\mdf@@myRad]P|-O);
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([xshift=\mdf@@myRad]O) -- ([xshift=\mdf@@myRad]O|-P);
  },
firstextra={
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=-\mdf@@myRad,xshift=2\mdf@@myRad]P-|O) -- ([yshift=-\mdf@@myRad,xshift=-2\mdf@@myRad]P);
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=-2\mdf@@myRad,xshift=-\mdf@@myRad]P) -- ([xshift=-\mdf@@myRad]P|-O);
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([xshift=\mdf@@myRad]O) -- ([yshift=-2\mdf@@myRad,xshift=\mdf@@myRad]O|-P);
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=\mdf@@myRad,yshift=-2\mdf@@myRad]P-|O) arc[start angle=-90,end angle=0] (P-|O); 
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=-\mdf@@myRad,yshift=-2\mdf@@myRad]P) arc[start angle=270,end angle=180] (P); 
  },
secondextra={
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=\mdf@@myRad,xshift=2\mdf@@myRad]O) -- ([yshift=\mdf@@myRad,xshift=-2\mdf@@myRad]P|-O);
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([xshift=-\mdf@@myRad]P) -- ([yshift=2\mdf@@myRad,xshift=-\mdf@@myRad]P|-O);
  \draw[\mdf@@myLineColor,line width=\mdf@@myLineWd,line cap=rect] ([yshift=2\mdf@@myRad,xshift=\mdf@@myRad]O) -- ([xshift=\mdf@@myRad]O|-P);
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=\mdf@@myRad,yshift=2\mdf@@myRad]O) arc[start angle=90,end angle=0] (O); 
  \draw[\mdf@@myLineColor,radius=\mdf@@myRad,line width=\mdf@@myLineWd,line cap=rect] ([xshift=-\mdf@@myRad,yshift=2\mdf@@myRad]P|-O) arc[start angle=90,end angle=180] (P|-O); 
  },
]{invcor}
\makeatother

\begin{document}

\begin{invcor}
\lipsum[4]
\end{invcor}

\begin{invcor}[
myLineColor=Dandelion,
myLineWd=3pt]
\lipsum[4]
\end{invcor}

\begin{invcor}[
myRad=10pt,
innerleftmargin=20pt,
innerrightmargin=20pt,
innertopmargin=20pt,
innerbottommargin=20pt,
myLineColor=Maroon,
linecolor=MidnightBlue,
linewidth=2pt,
myLineWd=3pt]
\lipsum[4]
\end{invcor}

\end{document}

在此处输入图片描述

答案3

使用包的轻量级方法图片:编辑:删除了多余的空格。

编辑2:在第二种方法中,需要填充内部和之后画出边框,起到\linethickness与第一幅图相同的作用。

\documentclass{article}
\usepackage{pict2e}
\usepackage{color}
\usepackage{lipsum}

\begin{document}
\setlength{\unitlength}{1cm}

\begin{picture}(10,5)
  \linethickness {.1\unitlength}%
  \roundcap
  \color[gray]{0.7}%
  \put (0,0){\arc[0,90]{1}}
  \Line (0,1)(0,4)
  \put (0,5){\arc[270,360]{1}}
  \Line (1,5)(9,5)
  \put (10,5){\arc[180,270]{1}}
  \Line (10,4)(10,1)
  \put (10,0){\arc[90,180]{1}}
  \Line (9,0)(1,0)
  \color{black}%
  \put (5,2.5){\makebox(0,0){\Huge\textsc{Albert Einstein}}}
\end{picture}

\bigskip
%alternative syntax allowing filling:
\begin{picture}(10,6)
  \linethickness {.1\unitlength}%
  \def\x {\moveto(1,0)
  \circlearc {0}{0}{1}{0}{90}
  \lineto(0,5)
  \circlearc {0}{6}{1}{-90}{0}
  \lineto(9,6)
  \circlearc {10}{6}{1}{180}{270}
  \lineto(10,1)
  \circlearc {10}{0}{1}{90}{180}
  \lineto(1,0)}%
  \color[rgb]{1,.95,0.95}%
  \x
  \fillpath
  \color[rgb]{0.7,0,0}%
  \x
  \strokepath
  \color{blue}%
  \put (5,3){\makebox(0,0){\parbox {8cm}{\footnotesize\lipsum[1]}}}  
\end{picture}

\end{document}

圆角盒子

相关内容