Skalierbares Rechteck mit doppeltem Rand

Skalierbares Rechteck mit doppeltem Rand

Wie kann ich ein Rechteck mit einem „Doppelrand“ zeichnen, bei dem für jeden seiner 8 (4 inneren und 4 äußeren) Ränder separat eine Farbe angegeben werden kann und bei dem der Abstand zwischen dem äußeren und dem inneren Rechteck beim Skalieren nicht größer wird resizebox?

(Entschuldigung, ich bin ganz neu bei TikZ.)

Ich habe Folgendes versucht, die Mängel sind: Es sind 3 „Rechtecke“ (innerer Rand ist gleich äußerer Rand) und seine Kanten scheinen „nicht verbunden“ zu sein:

\begin{tikzpicture}
  \draw[red, double = black] (0,0) -- (1,0);
  \draw[green, double = purple] (1,0) -- (1,1);
  \draw[blue, double = brown] (1,1) -- (0,1);
  \draw[yellow, double = white] (0,1) -- (0,0);
\end{tikzpicture}

Hier ist ein Bild, um das Problem zu veranschaulichen

Antwort1

Vielleicht das ?

Bildbeschreibung hier eingeben

\documentclass{article}
\usepackage{tikz,lipsum}
\usetikzlibrary{calc}

\usepackage[marginparsep=3pt, top=2cm, bottom=1.5cm, left=1.5cm, right=1.5cm]{geometry}

\makeatletter
\newcommand{\Square}[2]{%
    \def\@W{#1}%
    \begin{tikzpicture}[baseline=(current bounding box.base)]
    \foreach \o/\i [count=\j from 0] in {
        blue/red,
        yellow/black,
        orange/gray,
        green/violet}{%
    \fill[rotate=\j*90,\o]
        (-#2,-#2)--(#2,-#2)--(#2-\@W,\@W-#2)--(\@W-#2,\@W-#2)--cycle ;
    \fill[rotate=\j*90,\i]
        (-#2+\@W,-#2+\@W)--(#2-\@W,-#2+\@W)--(#2-2*\@W,2*\@W-#2)--(2*\@W-#2,2*\@W-#2)--cycle ;
        }
    \end{tikzpicture}
}
\makeatother


\newlength{\MyHeight}
\newsavebox{\MyBox}

\newcommand{\DBbox}[3][.05]{%
    \begin{lrbox}{\MyBox}
    \fbox{%
        \begin{minipage}{#2}
        #3
        \end{minipage}  
    }%
    \end{lrbox}%
    \settoheight{\MyHeight}{\usebox{\MyBox}}%
    \addtolength{\MyHeight}{-.2\baselineskip}% <- WHY ???
    \usebox{\MyBox}%
    \raisebox{.2\baselineskip}{\Square{#1}{\MyHeight}}% <- WHY ???
    }

\begin{document}

\DBbox[5pt]{9cm}{%
    \lipsum[1]}

\bigskip 

\DBbox[20pt]{7cm}{%
    \lipsum[1]}

\end{document}

Mehr Zeug :

Bildbeschreibung hier eingeben

\documentclass[margin=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\makeatletter
\newcommand{\Square}[5][%
        blue/red,
        yellow/black,
        orange/gray,
        green/violet%
        ]{%
        \pgfpointdiff{\pgfpointanchor{#3}{center}}
                 {\pgfpointanchor{#4}{center}}
        \pgf@xa=\pgf@x
        \pgf@ya=\pgf@y
        \pgfmathparse{veclen(\pgf@xa,\pgf@ya)/2.82843}
        \let\@L\pgfmathresult
    \def\@W{#2}% epaisseur
    %\def\@L{#3}% côté
    \begin{scope}[shift={($(#3)!.5!(#4)$)}]
    \node {#5} ;
    \foreach \o/\i [count=\j from 0] in {#1}{%
    \fill[rotate=\j*90,\o]
        (-\@L pt,-\@L pt)--(\@L pt,-\@L pt)--(\@L-\@W,\@W-\@L)--(\@W-\@L,\@W-\@L)--cycle ;
    \fill[rotate=\j*90,\i]
        (-\@L+\@W,-\@L+\@W)--(\@L-\@W,-\@L+\@W)--(\@L-2*\@W,2*\@W-\@L)--(2*\@W-\@L,2*\@W-\@L)--cycle ;
        }       
    \end{scope}
}
\makeatother


\begin{document}
\begin{tikzpicture}

\coordinate (A) at (0,0) ;
\coordinate (B) at (5,5) ;
\coordinate (C) at (3,-3) ;

    \Square{8pt}{A}{B}{Text 2} ;
    \Square[
        red/orange,
        yellow!30!green/gray,
        blue!25/black,
        violet/green%   
    ]{5pt}{A}{C}{Text 1} ;
\end{tikzpicture}
\end{document}

verwandte Informationen