使用 mdframed 和 TikZ (或 tcolorbox)在两侧绘制线条

使用 mdframed 和 TikZ (或 tcolorbox)在两侧绘制线条

我想在文本的两侧(左侧和右侧)画一条波浪线。

下面是一个 MWE,其中左侧有一行。我不知道如何在右侧添加一行。事实上,我找不到有关此(O) -- (O|-P)语法的任何文档。

我愿意接受任何解决方案,例如 的解决方案tcolorbox

\documentclass{article}

\usepackage{kantlipsum}

\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{shapes, decorations.pathmorphing, decorations.shapes, backgrounds, calc}

\newenvironment{myBox}{}{}

% see: https://tex.stackexchange.com/a/114161/8323
\newcommand\wavydecor{%
    \draw[decoration = {coil, 
                        aspect = 0.2, 
                        segment length = 5pt, 
                        amplitude = 1.5pt}, 
          decorate, line width = 0.7pt, black]
     (O) -- (O|-P);
}

\mdfdefinestyle{wavyLine}{%
usetwoside          = true,
hidealllines        = true,
innerleftmargin     = 5mm,
innerrightmargin    = 4mm,
rightmargin         = 2mm,
singleextra         = {\wavydecor},
firstextra          = {\wavydecor},
secondextra         = {\wavydecor},
middleextra         = {\wavydecor},
fontcolor           = black, 
backgroundcolor     = white, 
splittopskip        = 5mm
}

\surroundwithmdframed[style = wavyLine, needspace = 1.5cm]{myBox}

\begin{document}

\begin{myBox}
\kant[1]
\end{myBox}

\end{document}

在此处输入图片描述

答案1

O 和 P 是框架的两个对角

O=西南,P=东北

您的例子改为从西南到东南的线

在此处输入图片描述

\documentclass{article}

\usepackage{kantlipsum}

\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{shapes, decorations.pathmorphing, decorations.shapes, backgrounds, calc}

\newenvironment{myBox}{}{}

% see: https://tex.stackexchange.com/a/114161/8323
\newcommand\wavydecor{%
    \draw[decoration = {coil, 
        aspect = 0.2, 
        segment length = 5pt, 
        amplitude = 1.5pt}, 
    decorate, line width = 0.7pt, black]
    (O) -- (O-|P);
}

\mdfdefinestyle{wavyLine}{%
    usetwoside          = true,
    hidealllines        = true,
    innerleftmargin     = 5mm,
    innerrightmargin    = 4mm,
    rightmargin         = 2mm,
    singleextra         = {\wavydecor},
    firstextra          = {\wavydecor},
    secondextra         = {\wavydecor},
    middleextra         = {\wavydecor},
    fontcolor           = black, 
    backgroundcolor     = white, 
    splittopskip        = 5mm
}

\surroundwithmdframed[style = wavyLine, needspace = 1.5cm]{myBox}

\begin{document}
    
    \begin{myBox}
        \kant[1]
    \end{myBox}
    
\end{document}

或从西南向东北

在此处输入图片描述

\documentclass{article}

\usepackage{kantlipsum}

\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{shapes, decorations.pathmorphing, decorations.shapes, backgrounds, calc}

\newenvironment{myBox}{}{}

% see: https://tex.stackexchange.com/a/114161/8323
\newcommand\wavydecor{%
    \draw[decoration = {coil, 
        aspect = 0.2, 
        segment length = 5pt, 
        amplitude = 1.5pt}, 
    decorate, line width = 0.7pt, black]
    (O) -- (P);
}

\mdfdefinestyle{wavyLine}{%
    usetwoside          = true,
    hidealllines        = true,
    innerleftmargin     = 5mm,
    innerrightmargin    = 4mm,
    rightmargin         = 2mm,
    singleextra         = {\wavydecor},
    firstextra          = {\wavydecor},
    secondextra         = {\wavydecor},
    middleextra         = {\wavydecor},
    fontcolor           = black, 
    backgroundcolor     = white, 
    splittopskip        = 5mm
}

\surroundwithmdframed[style = wavyLine, needspace = 1.5cm]{myBox}

\begin{document}
    
    \begin{myBox}
        \kant[1]
    \end{myBox}
    
\end{document}

在此处输入图片描述

\documentclass{article}

\usepackage{kantlipsum}

\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{shapes, decorations.pathmorphing, decorations.shapes, backgrounds, calc}

\newenvironment{myBox}{}{}

% see: https://tex.stackexchange.com/a/114161/8323
\newcommand\wavydecor{%
    \draw[decoration = {coil, 
        aspect = 0.2, 
        segment length = 5pt, 
        amplitude = 1.5pt}, 
    decorate, line width = 0.7pt, black]
    (O) -- (O|-P);
    \draw[decoration = {coil, 
        aspect = 0.2, 
        segment length = 5pt, 
        amplitude = 1.5pt}, 
    decorate, line width = 0.7pt, black]
    (P) -- (O-|P);
}

\mdfdefinestyle{wavyLine}{%
    usetwoside          = true,
    hidealllines        = true,
    innerleftmargin     = 5mm,
    innerrightmargin    = 4mm,
    rightmargin         = 2mm,
    singleextra         = {\wavydecor},
    firstextra          = {\wavydecor},
    secondextra         = {\wavydecor},
    middleextra         = {\wavydecor},
    fontcolor           = black, 
    backgroundcolor     = white, 
    splittopskip        = 5mm
}

\surroundwithmdframed[style = wavyLine, needspace = 1.5cm]{myBox}

\begin{document}
    
    \begin{myBox}
        \kant[1]
    \end{myBox}
    
\end{document}

答案2

这是一个tcolorbox基于 的替代方案:

在此处输入图片描述

\documentclass[a4paper,12pt]{article}
\usepackage[many]{tcolorbox}
\usepackage{kantlipsum}
\usetikzlibrary{shapes, decorations.pathmorphing, decorations.shapes}


\begin{document}


\tikzset{mywavyline/.style={%
    decoration = {%
        coil, %
        aspect = 0.2, %
        segment length = 5pt,% 
        amplitude = 1.5pt},% 
    decorate, %
    line width = 0.7pt, %
    black%
    }}



\newtcolorbox{mybox}{%
    colback=white,%
    enhanced,%
    frame hidden,%
    overlay={%
        \draw[mywavyline] (frame.south west) -- (frame.north west);%
        \draw[mywavyline] (frame.north east) -- (frame.south east); %
    }}

\begin{mybox}
    \kant[1]
\end{mybox}
\end{document}

相关内容