4

I would like to draw a wavy line on both sides (left and right) of a text.

Below is a MWE in which there is a line on the left. I don't know how to add a line on the right. Indeed, I can't find any documentation about this (O) -- (O|-P) syntax.

I'm open to any solution, for instance a solution with 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}

enter image description here

4
  • The (A|-B) syntax says use the x coordinate of the node A and the y coordinate of the node B, similarly (A-|B) says use the x coordinate of B and the y coordinate of A.
    – Willoughby
    Mar 21, 2021 at 13:21
  • 1
    Thanks! Do you know what are O and P?
    – Colas
    Mar 21, 2021 at 13:24
  • mdframed with bracket both sides -- tex.stackexchange.com/questions/158649/…
    – js bibra
    Mar 21, 2021 at 13:32
  • @Colas simply iterating with the corner coordinates gives the solution below in the answer -- have a look
    – js bibra
    Mar 21, 2021 at 13:43

2 Answers 2

6

O and P are the two opposite corners of the frame

O=south west and P=north east

your example changed for line from south west -- south east

enter image description here

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

or from south west to north east

enter image description here

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

enter image description here

\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}
1
  • 2
    Wraping up the both \draw commands in one is also OK, with ending it by (O|-P) -- (O) (P) -- (O-|P);
    – SebGlav
    Mar 21, 2021 at 14:06
4

Here's a tcolorbox-based alternative:

enter image description here

\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}
1
  • and as @SebGlav said it can be also overlay={% \draw[mywavyline] (frame.south west) -- (frame.north west)(frame.north east) -- (frame.south east);%
    – js bibra
    Mar 21, 2021 at 15:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .