使用 mdframed 制作的长文本与使用 Mathcha 制作的灰色矩形重叠

使用 mdframed 制作的长文本与使用 Mathcha 制作的灰色矩形重叠

我有这个代码,

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage[framemethod=Tikz]{mdframed}
\begin{document}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt        
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%uncomment if require: \path (0,300); %set diagram left start at 0, and has height of 300

%Shape: Rectangle [id:dp7242002605277424] 
\draw  [fill={rgb, 255:red, 219; green, 219; blue, 219 }  ,fill opacity=1 ][line width=0.75]  (123,25) -- (563.5,25) -- (563.5,276.71) -- (123,276.71) -- cycle ;
%Shape: Rectangle [id:dp15046039100295516] 
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=1 ] (563.5,276.71) -- (563.5,293) -- (514.51,293) -- (514.51,276.71) -- cycle ;
%Shape: Rectangle [id:dp7536303834926936] 
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=1 ] (563.5,214.37) -- (579.5,214.37) -- (579.5,293) -- (563.5,293) -- cycle ;
%Shape: Rectangle [id:dp955510069108573] 
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=1 ] (107,8.71) -- (123,8.71) -- (123,87.34) -- (107,87.34) -- cycle ;
%Shape: Rectangle [id:dp2936063286787003] 
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=1 ] (171.99,8.71) -- (171.99,25) -- (123,25) -- (123,8.71) -- cycle ;
% Text Node
\draw (196,121) node [anchor=north][inner sep=0.75pt]  [font=\Huge] [align=left] {Here text};
\end{tikzpicture}
\end{document}

在此处输入图片描述

使用 Mathcha 创建。我想将使用 mdframed 创建的矩形放入灰色矩形中。可以吗?如果我放入此处输入文字环境

\draw (196,121) node [anchor=north][inner sep=0.75pt]  [font=\Huge] [align=left] {\begin{mdframed} Here text \end{mdframed}};

完成后mdframed我得到很多错误。

相关问题:堆叠盒子来装饰框架盒子的角落

答案1

尝试。当前限制:如果小于指定高度减去角矩形的 y 轴偏移量,则tcolorbox输出不“负责”。tcolorbox

\documentclass{article}
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{hooks, skins}

\usepackage[pass, showframe]{geometry}
\usepackage{lipsum}

\makeatletter
\tcbset{
  corner rect xshift/.store in=\tcb@rect@xshift,
  corner rect yshift/.store in=\tcb@rect@yshift,
  corner rect width/.store in=\tcb@rect@wd,
  corner rect height/.store in=\tcb@rect@ht,
  % init
  corner rect xshift=3pt,
  corner rect yshift=3pt,
  corner rect width=1cm,
  corner rect height=1cm
}

\newtcolorbox{mybox}[1][]{
  sharp corners,
  boxrule=.2mm,
  enhanced,
  #1,
  % adjust margins
  leftright skip=\tcb@rect@xshift,
  enlarge top by=\tcb@rect@yshift,
  enlarge bottom by=\tcb@rect@yshift,
  % draw filled squares
  interior code pre={
    \fill[black]
      ([shift={(-\tcb@rect@xshift,\tcb@rect@yshift)}]frame.north west) rectangle +(\tcb@rect@wd, -\tcb@rect@ht)
      ([shift={(\tcb@rect@xshift,-\tcb@rect@yshift)}]frame.south east) rectangle +(-\tcb@rect@wd, \tcb@rect@ht);
  }
}
\makeatother


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

\begin{mybox}[corner rect width=.5cm, corner rect yshift=5pt]
  \lipsum[2]
\end{mybox}
\end{document}

在此处输入图片描述

(最外层框架为 创建的文本主体框架\usepackage[pass, showframe]{geometry})。

答案2

  • 抱歉,在这个简单的情况下,我看不出使用Mathcha程序和mdframed包有什么好处。
  • 纯 TikZ 中的框代码简单而简短
  • 因此,这个答案不能解决您的问题:-(,但是可以通过不同的方式产生所需的结果:
\documentclass[tikz,12pt, margin=3mm]{standalone}
\tikzset{
    every picture/.style={line width=0.75pt}
        } %set default line width to 0.75pt
\usepackage{lipsum}

\begin{document}
\begin{tikzpicture}[x=0.75pt,y=0.75pt,
                    node distance=0pt,
every node/.append style = {draw, fill=gray!39,
                            minimum height=250, text width=450,
                            inner sep=25pt, align=left}
                    ]
% rectangle
\node (n) {\lipsum[11]};
%
\draw[line width=12pt]
    ([shift={(-0.5\pgflinewidth,-50pt)}] n.north west) |-
    ([shift={( 40pt, 0.5\pgflinewidth)}] n.north west) 
 
    ([shift={( 0.5\pgflinewidth, 50pt)}] n.south east) |-
    ([shift={(-40pt,-0.5\pgflinewidth)}] n.south east);
\end{tikzpicture}
\end{document}

在此处输入图片描述

编辑: 上述解决方案尝试重现您问题中的图片。但是,您似乎正在寻找以下解决方案:

\documentclass[12pt]{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\usepackage{tikz}
\tikzset{
    every picture/.style={line width=0.75pt}
        } %set default line width to 0.75pt
\usepackage{lipsum}

\begin{document}
\noindent%
\begin{tikzpicture}[node distance=0pt,
every node/.append style = {draw, fill=gray!39,
                            minimum height=12pt, 
                            text width=\dimexpr\linewidth-66pt,
                            inner sep=25pt, align=left}
                    ]
% rectangle
\node (n) {\lipsum[11]};
%
\draw[line width=8pt]
    ([shift={(-0.5\pgflinewidth,-50pt)}] n.north west) |-
    ([shift={( 40pt, 0.5\pgflinewidth)}] n.north west) 
 
    ([shift={( 0.5\pgflinewidth, 50pt)}] n.south east) |-
    ([shift={(-40pt,-0.5\pgflinewidth)}] n.south east);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容